简体   繁体   English

在屏幕上旋转和平移UIImageView

[英]Rotate and translate UIImageView off and on screen

How can I rotate and translate a UIImageView off one side of the screen, then its coming back from the other side.. Lets say I have a Wheel that I want to rotate and translate from the middle then off the screen to the left, then its "coming back" from the right side and back the middle.. 我该如何旋转并从屏幕的一侧平移UIImageView,然后从另一侧返回UIImageView。可以说,我有一个Wheel要旋转,然后从中间旋转并平移,然后移至屏幕的左侧,然后它从右侧“回到”中间。

I used following code to rotate and translate it OFF the screen; 我使用以下代码旋转并在屏幕外平移;

        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 if this is the right way to go, so please help! Dunno如果这是正确的方法,所以请帮助!

try This, it will Work for you 试试这个,它将为您工作

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM