【发布时间】:2014-02-15 02:59:58
【问题描述】:
我有一个 UIPinchGestureRecognizer,我已将其添加到自定义 UIView 中,该 UIView 随后被添加为我的主视图的子视图。出于某种原因,当用户第一次尝试捏合时,不会检测到捏合手势,但会在以后的任何尝试中检测到。请参阅下面的代码,用户必须在打印出 nslog 之前至少触摸一次视图,然后用户再捏。
声明:
self.pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(expandAction:)];
self.pinchGesture.scale = 0.0;
self.pinchGesture.delegate = self;
[self addGestureRecognizer:self.pinchGesture];
行动:
-(void)expandAction:(UIPinchGestureRecognizer *)sender {
NSLog(@"pinch detected");
//stop reminding user
[self stopTimer:self.pinchExpandTimer];
[UIView animateWithDuration: 0.0
delay: 0.0
options: UIViewAnimationOptionTransitionCrossDissolve | UIViewAnimationOptionBeginFromCurrentState
animations: ^{
[self.pinchCircle1 removeFromSuperview];
[self.pinchCircle2 removeFromSuperview];
}
completion: ^(BOOL finished){
}];
//calculate progress
CGFloat progress = MIN(sender.scale/5, 1.0);
[self setPinchAnimationWithProgress:progress];
}
代表:
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark UIGestureRecognizer Delegate
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
return YES;
}
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}
基本上,感觉就像用户必须“选择”视图然后做手势才能被拾取。我尝试在视图上启用用户交互和/或设置第一响应者,但它仍然不起作用。如果有任何效果,则在此视图中使用其他手势识别器,但我认为它不应该。有人有什么想法吗?
【问题讨论】:
-
您使用
UIView animateWithDuration块而没有实际设置任何动画是否有原因(duration和delay都是0)? -
它会取消任何在新动画影响的元素上正在进行的动画。在这种情况下,如果检测到捏合手势,我想删除正在动画的项目。
标签: ios iphone objective-c cocoa-touch uigesturerecognizer