CAShapeLayer & CGAffineTransformMakeForRotation?
CAShapeLayer & CGAffineTransformMakeForRotation?
- Subject: CAShapeLayer & CGAffineTransformMakeForRotation?
- From: "Eric E. Dolecki" <email@hidden>
- Date: Mon, 7 Dec 2009 09:16:52 -0500
I am still on the analog clock thing here. I am drawing the hands of the
clock myself and would like to programmatically rotate them.
For instance this is how I am constructing the hour hand:
rootLayer = [CALayer layer];
rootLayer.frame = CGRectMake(240, 160, 240, 160);
self.view.layer addSublayer:rootLayer];
CGPoint center = CGPointMake(0, 0);
hourHandPath = CGPathCreateMutable();
CGPathMoveToPoint(hourHandPath, nil, center.x, center.y+10);
CGPathAddLineToPoint(hourHandPath, nil, center.x, center.y - 50);
CGPathCloseSubpath(hourHandPath);
hourHandLayer = [CAShapeLayer layer];
hourHandLayer.path = hourHandPath;
UIColor *myStrokeColor = [UIColor colorWithHue:0.2 saturation:1
brightness:0.1 alpha:1.0];
hourHandLayer.strokeColor = myStrokeColor.CGColor;
hourHandLayer.lineWidth = 3.0;
[rootLayer addSublayer:hourHandLayer];
Now I am attempting to initially set it rotation:
NSCalendar *gregorian = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];
unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit |
NSDayCalendarUnit | NSHourCalendarUnit| NSMinuteCalendarUnit
|NSSecondCalendarUnit;
NSDate *date = [NSDate date];
NSDateComponents *comps = [gregorian components:unitFlags fromDate:date];
int h = [comps hour];
int m = [comps minute];
int s = [comps second];
CGAffineTransform cgaRotateHr =
CGAffineTransformMakeRotation(DEGREES_TO_RADIANS( h*30+m/2 ));
CGAffineTransform cgaRotateMin =
CGAffineTransformMakeRotation(DEGREES_TO_RADIANS( m*6+s/10 ));
*//This is not working - must be another method to do this I am unaware of
at the moment...*
[hourHandLayer setTransform:cgaRotateHr];
What is the proper way to apply the rotation? A CABasicAnimation with a
duration of 0 and a repeat count of 0?
Thanks in advance,
Eric
_______________________________________________
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