动画完成后再执行方法的两个方法
2016-12-26 08:12 supper_Ho 阅读(960) 评论(0) 编辑 收藏 举报- (void)smallImg
{
// 执行动画
[UIView animateWithDuration:0.25 animations:^{
// 存放需要执行动画的代码
// 1.头像慢慢变为原来的位置和尺寸
self.iconBtn.frame = CGRectMake(85, 80, 150, 150);
// 2.阴影慢慢消失
self.cover.alpha = 0.0;
} completion:^(BOOL finished) {
// 动画执行完毕后会自动调用这个block内部的代码
// 3.动画执行完毕后,移除遮盖(从内存中移除)
[self.cover removeFromSuperview];
self.cover = nil;
}];
// 1.删除阴影
// [self.cover removeFromSuperview];
// self.cover = nil;
// 2.恢复头像原来的位置
// [UIView beginAnimations:nil context:nil];
// [UIView setAnimationDuration:1.0];
// [UIView setAnimationDelegate:self];
// [UIView setAnimationDidStopSelector:@selector(removeCover)];
// [UIView commitAnimations];
}
//- (void)removeCover
//{
// [self.cover removeFromSuperview];
// self.cover = nil;
//}
动画镶嵌
- (IBAction)download:(UIButton *)btn {
// 1.让按钮失效(文字变为"已下载")
btn.enabled = NO;
// 2.显示下载成功的信息("成功下载xxx")
UILabel *label = [[UILabel alloc] init];
label.text = [NSString stringWithFormat:@"成功下载%@", self.app.name];
label.font = [UIFont systemFontOfSize:12];
label.textAlignment = NSTextAlignmentCenter;
label.textColor = [UIColor whiteColor];
label.backgroundColor = [UIColor blackColor];
label.frame = CGRectMake(0, 0, 150, 25);
label.center = CGPointMake(160, 240);
label.alpha = 0.0;
// 巧妙利用控件的尺寸和圆角半径,能产生一个圆
label.layer.cornerRadius = 5;
// 超出主层边界的内容统统剪掉
// label.layer.masksToBounds = YES;
label.clipsToBounds = YES;
[self.superview addSubview:label];
// 3.动画
[UIView animateWithDuration:1.0 animations:^{
label.alpha = 0.5;
} completion:^(BOOL finished) {
[UIView animateWithDuration:1.0 delay:1.0 options:UIViewAnimationOptionCurveLinear animations:^{
label.alpha = 0.0;
} completion:^(BOOL finished) {
[label removeFromSuperview];
}];
}];
}