UIView动画With Block

来源:互联网 发布:science域名 编辑:程序博客网 时间:2024/05/29 04:35
- (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];        }    }];}

0 0
原创粉丝点击