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
    评论
在 Android 中,你可以使用属性动画或者补间动画来给一个 View 添加动画效果。 1. 使用属性动画(Property Animation): 属性动画可以让你对 View 的任意属性进行动画操作,包括位置、尺寸、透明度等。下面是一个简单的例子,演示如何使用属性动画来让一个 View 平移: ```java // 导入必要的类 import android.animation.ObjectAnimator; import android.view.View; // 获取要进行动画View View view = findViewById(R.id.your_view); // 创建属性动画对象,设置要操作的属性和值 ObjectAnimator animator = ObjectAnimator.ofFloat(view, "translationX", 0f, 200f); // 设置动画的持续时间 animator.setDuration(1000); // 启动动画 animator.start(); ``` 2. 使用补间动画(Tween Animation): 补间动画是一种基于预定义动画效果的方式,比如旋转、缩放、淡入淡出等。下面是一个简单的例子,演示如何使用补间动画来让一个 View 渐变消失: ```java // 导入必要的类 import android.view.animation.AlphaAnimation; import android.view.animation.Animation; import android.view.View; // 获取要进行动画View View view = findViewById(R.id.your_view); // 创建补间动画对象,设置动画效果 Animation animation = new AlphaAnimation(1.0f, 0.0f); // 设置动画的持续时间 animation.setDuration(1000); // 启动动画 view.startAnimation(animation); ``` 这只是两种常见的动画方式,你还可以通过组合动画、使用插值器等方式实现更复杂的效果。详细的动画操作可以参考 Android 官方文档。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值