NB: This is for a Cocoa app on OS X, NOT iOS.
I have a layer-backed NSButton (subclass of NSView). What I want to do is rotate that button using Core Animation. I'm using the following code to do it:
让NSView围绕中心点旋转,只要注意view中layer的anchorPoint即可,下面是代码片段,最后跟着的是stackoverflowd的帖子
NSImage *rimage = rb.GetNativeImageNamed(IDR_X115_CHECK_VERSION_LOADING).ToNSImage();
rotatoinWidth_ = [rimage size].width;
rotationImageView.reset([[[NSImageViewalloc] initWithFrame:NSMakeRect(196,156+rotatoinWidth_/2.0,rotatoinWidth_, rotatoinWidth_)]autorelease]);
[selfaddSubview:rotationImageView];
[rotationImageViewsetImage:rimage];
[selfsetWantsLayer:YES];
[rotationImageViewsetWantsLayer:YES];
CABasicAnimation *animation = [CABasicAnimation
animationWithKeyPath: @"transform" ];
animation.fromValue = [NSValuevalueWithCATransform3D:CATransform3DIdentity];
//围绕Z轴旋转,垂直与屏幕
animation.toValue = [NSValue valueWithCATransform3D:
CATransform3DMakeRotation(M_PI,0.0, 0.0,1.0) ];
animation.duration =1;
animation.cumulative =YES;
animation.repeatCount =100000;
[rotationImageViewlayer].anchorPoint =CGPointMake(0.5,0.5);
[[rotationImageViewlayer] addAnimation:animationforKey:nil];
3
2
|
NB: This is for a Cocoa app on OS X, NOT iOS. I have a layer-backed NSButton (subclass of NSView). What I want to do is rotate that button using Core Animation. I'm using the following code to do it: |