- (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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.