iphone - 在屏幕上旋转和平移UIImageView

标签 iphone ios animation uiimageview cabasicanimation

如何旋转并在屏幕的一侧平移UIImageView,然后从另一侧返回。
可以说,我有一个要旋转的轮子,该轮子要从中间旋转并平移,然后从屏幕移到左侧,然后从右侧“返回”并回到中间。

我使用以下代码旋转并在屏幕外平移;

        CABasicAnimation* rotationAnimation;
        rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
        rotationAnimation.toValue = [NSNumber numberWithFloat: -M_PI * 2.0 /* full rotation*/ * 2 * 1 ];
        rotationAnimation.duration = 1;
        rotationAnimation.cumulative = YES;
        rotationAnimation.repeatCount = 1.0; 
        rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
        rotationAnimation.delegate = self;

        CABasicAnimation* translationAnimation;
        translationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
        translationAnimation.toValue = [NSNumber numberWithFloat:-700];
        translationAnimation.duration = 1;
        translationAnimation.cumulative = YES;
        translationAnimation.repeatCount = 1.0; 
        translationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
        translationAnimation.removedOnCompletion = NO;
        translationAnimation.fillMode = kCAFillModeForwards;

Dunno如果这是正确的方法,所以请帮助!

最佳答案

试试这个,它将为您工作

  CABasicAnimation* rotationAnimation;
    rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    rotationAnimation.toValue = [NSNumber numberWithFloat: -M_PI * 2.0 /* full rotation*/ * 2 * 1 ];
    rotationAnimation.duration = 1;
    rotationAnimation.cumulative = YES;
    rotationAnimation.repeatCount = 1.0; 
    rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
    rotationAnimation.delegate = self;

    CABasicAnimation* translationAnimation;
    translationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
    translationAnimation.toValue = [NSNumber numberWithFloat:-700];
    translationAnimation.duration = 1;
    translationAnimation.cumulative = YES;
    translationAnimation.repeatCount = 1.0; 
    translationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
    translationAnimation.removedOnCompletion = NO;
    translationAnimation.fillMode = kCAFillModeForwards;



    CAAnimationGroup *group = [CAAnimationGroup animation];
    group.animations = [NSArray arrayWithObjects:rotationAnimation,translationAnimation, nil];
    group.delegate = self;
    group.removedOnCompletion = NO;
    group.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

    [[self.imageView.layer addAnimation:group forKey:@"randt"];

关于iphone - 在屏幕上旋转和平移UIImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8877584/

相关文章:

android - 使用 Android 动画,情绪从中心向右滚动

ios - 如何支持 iOs 9 功能,同时保持对 iOs 8 的支持?

iphone - 核心数据通过两个描述符对数据进行排序

ios - Xcode 7 GM 创建了通用存档而不是 iOS 应用程序存档

ios - 如何在 iphone 中以编程方式隐藏键盘

css - 如何同时为具有一个计时功能的 translateX 添加转换和为具有另一个计时功能的 translateY 添加转换?

java - 设置动画反向移动并在单击按钮时显示类中的形状

iphone - 是否有通过打开应用程序一部分的 web View 创建链接?

ios 验证 : Invalid image path - missing icon file

ios - 在 NSURLSessionData 的实现中未调用委托(delegate)方法