Rit*_*its 12 iphone cocoa-touch core-animation objective-c uiview
在我看来,这两个类方法是不可互换的.我有一个UIView的子视图,在touchesBegan方法中有以下代码:
if (!highlightView) {
UIImageView *tempImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Highlight"]];
self.highlightView = tempImageView;
[tempImageView release];
[self addSubview:highlightView];
}
highlightView.alpha = 0.0;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
highlightView.alpha = 1.0;
[UIView commitAnimations];
Run Code Online (Sandbox Code Playgroud)
当我触摸按钮时,高光渐渐消失,就像你期望的那样.当我立即触摸时(在动画完成之前),我的touchesEnded被调用.这是我想要的行为.
但是现在,我已经成为了块的忠实粉丝,并试图尽可能地使用它们.所以我用这个取代了UIView动画代码:
[UIView animateWithDuration:0.2 animations:^{
highlightView.alpha = 1.0;
}];
Run Code Online (Sandbox Code Playgroud)
结果:亮点仍然淡入符合市场预期,但如果我摸了之前在动画结束后,我的touchesEnded并没有被调用.如果我润色后的动画结束后,我的touchesEnded 不会被调用.这里发生了什么?
Bol*_*ock 14
默认情况下,iOS 4中的新动画块会禁用用户交互.您可以传入一个选项,允许视图在动画期间使用位标志以及如下animateWithDuration:delay:options:animations:completion
方法响应触摸UIView
:
UIViewAnimationOptions options = UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction;
[UIView animateWithDuration:0.2 delay:0.0 options:options animations:^
{
highlightView.alpha = 1.0;
} completion:nil];
Run Code Online (Sandbox Code Playgroud)