![](/img/trans.png)
[英]Passing touches to parent view controller after finish of Gesture recognizer
[英]iOS gesture recognizer only starts after user touches view
我有一個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;
}
基本上,感覺用戶必須“選擇”視圖然后執行手勢才能將其拾取。 我嘗試在視圖上啟用用戶交互和/或設置第一響應者,但仍然無法正常工作。 如果有任何作用,此視圖中還會使用其他手勢識別器,但我認為不應該這樣做。 有人有什么想法嗎?
固定。 問題是初始化后,我立即在UIPinchGestureRecognizer上設置了scale屬性。 這可能是Apple代碼中的錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.