将 UIImageView 旋转并平移到屏幕外或屏幕上
如何在屏幕的一侧旋转并平移 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;
不知道这是否是正确的方法,所以请帮忙!
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..
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个,它会对你有用
try This, it will Work for you
Swift 5.4.2(基于 Sanjeev Rao 回复):
Swift 5.4.2 (based on Sanjeev Rao reply):