CAShapeLayer for Drawing Lines; Animations Skewed
CAShapeLayer for Drawing Lines; Animations Skewed
- Subject: CAShapeLayer for Drawing Lines; Animations Skewed
- From: Christopher J Kemsley <email@hidden>
- Date: Thu, 10 Sep 2009 19:20:59 -0700
Hi all,
In my current development project, I have numerous dots that will be
moved around periodically, each connected by a line.
The dots are represented as CALayers, with the "contents" set to a
simple 20x20 dot, and they are moved around by animating the
"position" property.
The connecting lines will be drawn between the centers of two dots,
and will be moved via an animations whenever the dots change position.
This is where I'm running into trouble. Any suggestions on how to fix
what I've done so far or suggestions for a different, easier approach
are more than welcome.
What I've tried:
CALayer with 50x1 Square as Contents
In this method, I used a 50x1 square. For every animation, I set the
bounds to:
CGRectMake ( 0 , 0 , absoluteDistanceBetweenPoints , 1 ) ;
and the transform to
CATransform3DMakeRotation ( angleBetweenPoints , 0 , 0 , 1 ) ;
This worked, but had the unfortunate side-effect of, during some of
the moves, rotating too far around in the wrong direction, making the
endpoints come out from under the points. (For example, instead of
rotating 90º, it would rotate 270º in the wrong direction. This, in
theory, is easy to fix, but isn't as easy as it sounds.
CAShapeLayer with Path from PointA to PointB
In this method, I used a CAShapeLayer with the correct color and a 1px
width. I made a path between the two points.
For moves, I created another path representing the new position and
used a CABasicAnimation to animate the "path" property.
This also 'works,' but also has a side-effect: A line, instead of
animating from (oldPointA,oldPointB) to (newPointA,newPointB) would
animate to (oldPointA,oldPointB) to (randomPoint,randomPoint) to
(newPointA,newPointB) (Note: (aPoint,bPoint) represents a line/
path from aPoint to bPoint)
Any suggestions for improving these methods (especially fixing the
CAShapeLayer, which would be optimal) would be greatly appreciated!
Thanks,
-Christopher_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden