您的位置:首页 > 产品设计 > UI/UE

[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]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: