I am rotating an NSImageView from its center which is working perfectly however when I start the animation the NSImageView hops from its location to a random location. I do not know why is it happening. Please help.
I am elaborating how I am doing it all. Also, I am providing a Github link so that you may run it if you want.
Code:
// on button press animation will be started
-(void)buttonPressed:(id)sender{
// setting the anchor point of the view
_img.layer.anchorPoint = CGPointMake(0.5f, 0.5f);
// calling the animation function
[self startRefreshAnimation];
}
// in order to repeate the animation
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
[self startRefreshAnimation];
}
// the function that will handel all the animation stuff
-(void)startRefreshAnimation {
CABasicAnimation *anim2 = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
anim2.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
NSNumber* toValue = [NSNumber numberWithFloat:0 * (M_PI / 180.0f)];
NSNumber* fromValue = [NSNumber numberWithFloat:(360.0f) * (M_PI / 180.0f)];
anim2.fromValue = toValue;
anim2.toValue = fromValue;
anim2.duration = 1.0f;
anim2.delegate = self;
[_img.layer addAnimation:anim2 forKey:@"transform"];
}