iphone – 像核心动画老虎机一样在z轴上旋转
我可以通过此代码在此处移动或动画我的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 clockwise carousel.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的“透视核心动画”,之前已经被问过).可能需要进行大量调整以获得正确的外观,但这应该足以让您入门. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- forms – 外部组件的React-bootstrap调用方法
- [Oracle] Io Error: The Network Adapter could not establ
- ios – 如何通过UI测试执行“向左滑动”操作
- c# – 使用JSON请求对象的WCF REST GET?
- c – 清漆排序查询字符串参数
- grep命令使用以及正则表达式简述
- Invalid Swift Support - The SwiftSupport folder is empt
- postgresql – 无法使用Cloudera Manager安装hadoop
- c# 动态加载dll文件,并实现调用其中的简单方法
- Ruby 使用 FTP 进行文件传输