I am having a cocoa mac application in objective c.
When I press my NSButton, I want to rotate it clockwise with animation for some seconds.
I tried below code but not working.
CABasicAnimation *ani = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
ani.fromValue = [NSNumber numberWithFloat:0];
ani.toValue = [NSNumber numberWithFloat:-M_PI*2];
[btnScan.layer setAnchorPoint:CGPointMake(0.5, 0.5)];
ani.duration = 2.0; // seconds
ani.repeatCount = HUGE_VAL;
[btnScan.layer addAnimation:ani forKey:nil];
I searched a lot but couldn't find a proper solution for this.
Can anyone help me on this, please?
Add
[btnScan setWantsLayer:YES];
before you do your animation. NSView unlike UIView doesn't have a backing layer by default.from Apple Docs: