[UIView beginAnimations:context:]与[UIView animateWithDuration:animations:]值得注意区别
2013-10-18 16:51
302 查看
看过官方文档的都知道,官方推荐在iOS4以后使用[UIView animateWithDuration:animations:],而不是原来的[UIView beginAnimations:context:],来完成动画,虽然二者功能几乎完全相同,但使用前者在一些情况下会方便不少,这些内容可以参考官方文档View
Programming Guide For iOS的Animation一节.
二者有一个值得新手注意的区别就是[UIView animateWithDuration:animations:]默认会禁止触摸,手势等的响应,这可以通过设置option选项来解决(直接引用StackOverFlow的一段了):
UIViewAnimationOptions options = UIViewAnimationCurveLinear | UIViewAnimationOptionAllowUserInteraction;
[UIView animateWithDuration:0.2 delay:0.0 options:options animations:^
{
highlightView.alpha = 1.0;
} completion:nil];
[UIView animateWithDuration:duration
delay:0.0
options:UIViewAnimationCurveEaseInOut //设置动画类型
animations:^{
//开始动画
[self updateArrowBtnTitle:YES];
rotateView.transform = CGAffineTransformMakeRotation((stickToDegrees/180)*M_PI);
}
completion:^(BOOL finished){
// 动画结束时的处理
}];
[UIView animateWithDuration:] 方法仅支持ios4.0及以上版本。如果要兼容以前的版本的话,还是需要使用 [UIView beginAnimation:] 方法
[UIView beginAnimations:nil context:nil];
// fade out
helpImageBtn.alpha = 0.0f;
// set animation did stop selector
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
[UIView commitAnimations];
- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
if (self.retainedHelpImageBtn.superview) [b]//先判断父视图再执行视图移除
[self.retainedHelpImageBtn removeFromSuperview];
}[/b]
Programming Guide For iOS的Animation一节.
二者有一个值得新手注意的区别就是[UIView animateWithDuration:animations:]默认会禁止触摸,手势等的响应,这可以通过设置option选项来解决(直接引用StackOverFlow的一段了):
UIViewAnimationOptions options = UIViewAnimationCurveLinear | UIViewAnimationOptionAllowUserInteraction;
[UIView animateWithDuration:0.2 delay:0.0 options:options animations:^
{
highlightView.alpha = 1.0;
} completion:nil];
[UIView animateWithDuration:duration
delay:0.0
options:UIViewAnimationCurveEaseInOut //设置动画类型
animations:^{
//开始动画
[self updateArrowBtnTitle:YES];
rotateView.transform = CGAffineTransformMakeRotation((stickToDegrees/180)*M_PI);
}
completion:^(BOOL finished){
// 动画结束时的处理
}];
[UIView animateWithDuration:] 方法仅支持ios4.0及以上版本。如果要兼容以前的版本的话,还是需要使用 [UIView beginAnimation:] 方法
[UIView beginAnimations:nil context:nil];
// fade out
helpImageBtn.alpha = 0.0f;
// set animation did stop selector
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
[UIView commitAnimations];
- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
if (self.retainedHelpImageBtn.superview) [b]//先判断父视图再执行视图移除
[self.retainedHelpImageBtn removeFromSuperview];
}[/b]
相关文章推荐
- User guide for Netty 4.x
- 如何自定义UIActionSheet(UIAlertView)中的内容
- UISlider滑块控件
- UIButton使用状态
- NGUI系列教程五(角色信息跟随)
- 条款20.宁以pass-by-reference-to-const替换pass-by-vlaue
- EasyUi_学习之路_06
- UITableView中间加入文字
- 一套生产系统UI
- EasyUi_学习之路_05
- UItableView中含输入框(TextField)被键盘遮挡问题
- HDU 2255(KM) - from lanshui_Yang
- Windows phone UI流畅度优化
- UIView大小缩放的动画效果函数
- UIView大小缩放的动画效果函数
- double zhuanhuawei uint8
- android AsyncQueryHandler的分析
- 问题:Unknown class ZBarReaderView in Interface Builder file.
- UESTC 1501 - Defense Lines 离散化+线段树优化DP
- Cassandra Query Language (CQL) v2.0