- (void)viewDidLoad
{
[super viewDidLoad];
self.smallRect = CGRectMake(0, 0, 20, 30);
self.bigRect = CGRectMake(0, 0, 200, 300);
//创建一个按钮
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.backgroundColor = [UIColor lightGrayColor];
[btn addTarget:self action:@selector(onPressButton:) forControlEvents:UIControlEventTouchUpInside];
btn.frame = CGRectMake(150, 300, 120, 30);
[self.view addSubview:btn];
//创建imgView
self.imgview = [[UIImageView alloc] initWithFrame:_smallRect];
_imgview.backgroundColor = [UIColor redColor];
[self.view addSubview:_imgview];
}
//button触发事件
-(void)onPressButton:(id)sender
{
//*************第一种 动画blcok **********
[UIView animateWithDuration:2 animations:^{
_imgview.frame = self.bigRect;
}];
//*************第二种 动画blcok **********
//带一个回调
[UIView animateWithDuration:2 animations:^{
self.imgview.frame = self.bigRect;
} completion:^(BOOL finished) {
self.imgview.backgroundColor = [UIColor blackColor];
}];
//*************第三种 动画blcok **********
//带一个延迟
[UIView animateWithDuration:2 delay:5 options:UIViewAnimationOptionAutoreverse animations:^{
self.imgview.frame = self.bigRect;
} completion:^(BOOL finished) {
if (finished) {
self.imgview.backgroundColor = [UIColor blackColor];
}
}];
}
UIView动画With Block
最新推荐文章于 2022-09-25 15:03:41 发布