【发布时间】:2010-10-09 18:17:23
【问题描述】:
在我看来这两个类方法是不可互换的。我有一个 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];
当我触摸 Button 时,高亮会淡入,正如您所期望的那样。当我立即触摸时(在动画完成之前),我的 touchesEnded 被调用。这是我想要的行为。
但是现在,我已经成为积木的忠实粉丝,并尝试尽可能地使用它们。所以我用这个替换了 UIView 动画代码:
[UIView animateWithDuration:0.2 animations:^{
highlightView.alpha = 1.0;
}];
结果:高光仍按预期淡入,但如果我在动画完成之前 触摸,我的 touchesEnded not 会被调用。如果我在动画完成后 触摸,我的 touchesEnded 确实 会被调用。这是怎么回事?
【问题讨论】:
-
手指,对不起。释放 = 修饰
标签: iphone objective-c cocoa-touch uiview core-animation