【发布时间】:2012-07-26 04:04:48
【问题描述】:
我正在使用animateWithDuration: 为几个视图设置动画,但我根本无法检测到对它们的任何触摸。
我尝试过简单的触摸处理 (touchesEnded:) 和 tapGestureRecognizer。
首先我用CGAffineTransformTranslation 为它们设置了动画,但后来我意识到如果我用touchesMoved: 检查坐标就不会这样,所以我切换到为 frame 属性设置动画。我很快注意到,帧值在动画期间并没有真正改变,所以我放弃了 touchesEnded: 想法。所以我改成了一个也不起作用的tapGestureRecognizer。
我已经在所有视图上启用了 userInteraction,并且我还在动画中添加了选项 UIViewAnimationOptionAllowUserInteraction。
这是动画的代码和之前发生的事情:
// init the main view
singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapOnItem:)]; // singleFingerTap is an ivar
// code somewhere:
// userItem is a subview of MainView
[userItem addGestureRecognizer:singleFingerTap];
[UIView animateWithDuration:animationTime
delay:0.0f
options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction
animations:^{
userItem.frame = CGRectMake(-(self.bounds.size.width + userItem.frame.size.width), userItem.frame.origin.y, userItem.frame.size.width, userItem.frame.size.height);
}
completion:^(BOOL finished) {
if (finished) {
[unusedViews addObject:userItem];
[userItem removeFromSuperview];
[userItem removeGestureRecognizer: singleFingerTap];
}
}
];
这是手势识别器:
- (void) handleTapOnItem:(UITapGestureRecognizer *)recognizer{
NSLog(@"Touched");
}
那么,我如何才能真正从动画视图中获得触摸,或者最好的解决方案是什么? 向每个视图添加透明 uibutton 不是一种选择。 :(
【问题讨论】:
标签: iphone cocoa uiview touch uiviewanimation