mac 如何实现一个view自转的动画

让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];




http://stackoverflow.com/questions/14839335/core-animation-set-anchorpoint-on-10-8-to-rotate-a-layer-about-its-center

Core Animation: set anchorPoint on 10.8 to rotate a layer about its center

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:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值