您的位置:首页 > 产品设计 > UI/UE

UIView的简单动画

2016-11-04 18:36 260 查看

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);
}];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  uiview 动画