旋转动画xcode iphone
发布时间:2020-12-14 17:29:30 所属栏目:百科 来源:网络整理
导读:我试图使用 xcode中的简单单一视图应用程序围绕圆圈旋转图像.我在主故事板上有一个圆圈图像和一个按钮.我使用下面的代码,但圆形图像向下漂移,然后向左旋转,随着它的旋转.我不确定它缺少什么. 谢谢你的帮助. ViewController.h #import UIKit/UIKit.h @interfa
我试图使用
xcode中的简单单一视图应用程序围绕圆圈旋转图像.我在主故事板上有一个圆圈图像和一个按钮.我使用下面的代码,但圆形图像向下漂移,然后向左旋转,随着它的旋转.我不确定它缺少什么.
谢谢你的帮助. ViewController.h #import <UIKit/UIKit.h> @interface ViewController : UIViewController { IBOutlet UIImageView *theImageView; IBOutlet UIButton *theButton; NSTimer *theTimer; float angle; BOOL runStop; } @property (atomic,retain) IBOutlet UIImageView *theImageView; @property (atomic,retain) IBOutlet UIButton *theButton; -(IBAction)runRoulette:(id)sender; @end ViewController.m #import "ViewController.h" @interface ViewController () @end @implementation ViewController @synthesize theButton,theImageView; - (void)viewDidLoad { angle = 0; runStop = FALSE; [super viewDidLoad]; // Do any additional setup after loading the view,typically from a nib. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(void)rotateRoulette { theImageView.center = CGPointMake(self.theImageView.center.x,self.theImageView.center.y); theImageView.transform=CGAffineTransformMakeRotation (angle); angle+=0.001; } -(IBAction)runRoulette:(id)sender { if(!runStop) { theTimer = [NSTimer scheduledTimerWithTimeInterval:1.0/600.0 target:self selector:@selector(rotateRoulette) userInfo:nil repeats:YES]; } else { [theTimer invalidate]; theTimer = nil; } runStop = !runStop; } @end 解决方法
我找到了一种非常简单的方法来让我的动画工作我也想要它 –
theImageView.center = CGPointMake(160.0,364.0); [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:5]; //theImageView.center=CGPointMake(self.theImageView.center.x,self.theImageView.center.y); theImageView.transform = CGAffineTransformMakeRotation(M_PI/2.65); [UIView commitAnimations]; 它旋转theImageView M_PI / 2.65(M_PI / 2.65是roataion数量),计数为5. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- c# – 我的彩虹拾色器不能正确饱和,我错过了什么/做错了什么
- 解决ajax修改数据库后_再次刷新还是原来的数据的问题
- sqlite判断数据库表名是否存在
- React 教程第十三篇 —— Redux 跨组件通信进阶之 Provider
- 是什么导致我的Ruby`track`块中出现这种死锁?
- C#包装器的c dll; “运行时检查失败#0 – ESP的值未在函数调
- c# – 使用没有id索引的列表加入Linq
- Vue引入jquery实现平滑滚动到指定位置
- c# – 即使内存可用,MemoryFailPoint总是会抛出一个Insuffi
- iphone – 使用Xcode创建无线清单文件(.plist Extension)