iphone – 像核心动画老虎机一样在z轴上旋转

iphone – 像核心动画老虎机一样在z轴上旋转,第1张

概述我可以通过此代码在此处移动或动画我的UIView: - (void) makeAnim1{ //downward animation [UIView animateWithDuration:1.5 delay:0.15 options: UIViewAnimationCurveL 我可以通过此代码在此处移动或动画我的UIVIEw:

- (voID) makeAnim1{    //downward animation     [UIVIEw animateWithDuration:1.5                          delay:0.15                        options: UIVIEwAnimationCurvelinear                     animations:^{                         carousel.frame = CGRectOffset(carousel.frame,650);                     }                     completion:^(BOol finished){ //task after an animation ends                         [self performSelector:@selector(makeAnim1_1) withObject:nil afterDelay:2.0];                         NSLog(@"Done!");                     }];    }- (voID) makeAnim1_1{    //upward animation    [UIVIEw animateWithDuration:1.5                          delay:0.1                        options: UIVIEwAnimationCurvelinear                     animations:^{                         carousel.frame = CGRectOffset(carousel.frame,-650);                     }                      completion:^(BOol finished){                        NSLog(@"Done!");                     }];    }

但它只会上下移动UIVIEw.如何让它像Slot机器一样旋转,但只包含一个图像或视图.像在z轴上旋转一样.但要让它看起来像包含多个图像.

谢谢您的帮助.

解决方法 您可以更改变换,而不是更改动画块内的帧.变换可用于缩放,旋转和平移(移动)视图.您只能围绕z轴旋转,但这就是您要求的.视图上的transform属性采用CGAffinetransform,如下所示:

// rotate pi/2 degrees clockwisecarousel.transform = CGAffinetransformMakeRotation(M_PI_2);

如果你需要进行更高级的变换,比如围绕另一个轴旋转,那么你需要使用一点Core Animation并设置vIEws层的transform属性(它采用CAtransform3D而不是CGAffinetransform).

与所有Core Animation代码一样,您需要导入QuartzCore.framework并在代码中包含QuartzCore / QuartzCore.h.

您正在进行的上述动画是UIVIEw动画,这些动画仅用于为视图设置动画,但您要求的动画需要更高级的视图层动画.我建议您查看CABasicAnimation的文档,还可以查看iOS核心动画编程指南以了解更多信息.

您可以为视图图层的x旋转设置动画,如下所示:

CABasicAnimation *slotAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.x"];[slotAnimation setTovalue:[NSNumber numberWithfloat:M_PI_2]];// animation customizations like duration and timing // that you can read about in the documentation [[carousel layer] addAnimation:slotAnimation forKey:@"mySlotAnimation"];

上面的代码确实会围绕x轴旋转视图,但是在没有透视的情况下看起来会非常愚蠢(搜索SO的“透视核心动画”,之前已经被问过).可能需要进行大量调整以获得正确的外观,但这应该足以让您入门.

总结

以上是内存溢出为你收集整理的iphone – 像核心动画老虎机一样在z轴上旋转全部内容,希望文章能够帮你解决iphone – 像核心动画老虎机一样在z轴上旋转所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1042079.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存