UIView的简单动画

来源:互联网 发布:js变量为空 编辑:程序博客网 时间:2024/04/29 03:19

UIView的简单动画

//方法1

//设置简单动画//1.开始动画[UIView beginAnimations:nil context:nil];//2.持续时间[UIView setAnimationDuration:2.0];//3.动画效果fatherView.center = CGPointMake(self.view.frame.size.width / 2, self.view.frame.size.height / 2);//4.提交动画[UIView commitAnimations];

//方法2

[UIView animateWithDuration:1.0 animations:^{    //动画效果    fatherView.center = CGPointMake(self.view.frame.size.width / 2, self.view.frame.size.height / 2);} completion:^(BOOL finished) {    //动画结束时调用    fatherView.frame = CGRectMake(0, 0, 200, 200);}];

UIView简单动画test

- (void)viewDidLoad {[super viewDidLoad];// Do any additional setup after loading the view, typically from a nib._view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];_view.backgroundColor = [UIColor redColor];[self.view addSubview:_view];[NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(timeGo) userInfo:nil repeats:YES];}- (void)timeGo{[UIView animateWithDuration:2.0 animations:^{    _view.center = CGPointMake(self.view.frame.size.width / 2, self.view.frame.size.height / 2);} completion:^(BOOL finished) {    _view.frame = CGRectMake(0, 0, 100, 100);}];}
1 0
原创粉丝点击