Reputation: 23
I have a clock needle image with size 12x44.The below code is what i have tried to rotate it in clock direction
Code :
-(void)rotationLargeAnimation:(UIView *) itemView withDuration:(float) durat withDirection:(int)intDirect {
CABasicAnimation *rotation1 = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
rotation1.fromValue = [NSNumber numberWithFloat:0];
rotation1.toValue = [NSNumber numberWithFloat:(2*M_PI)];
rotation1.duration = durat; // Speed
rotation1.repeatCount = HUGE_VALF; // Repeat forever. Can be a finite number.
itemView.layer.anchorPoint = CGPointMake(0.5,0.2);
[itemView.layer addAnimation:rotation1 forKey:@"Spin"];
}
When rotating clock needle it is rotating based on top position.How do i rotate needle based on bottom position.any help appreciated.thanks in advance.
Upvotes: 1
Views: 1880
Reputation: 1090
Anchor point sets the point around which layer is rotating in normalized coordinates (0, 0) is top left corner, (0.5, 0.5) is center (default), (1.0, 1.0) is bottom right corner. So you probably want to set it somewhere around (0.5, 1.0) this is center in X axis and bottom in Y axis (probably there will be offset from bottom depending on what shape is your needle).
Upvotes: 2