0
我有一個UIPinchGestureRecognizer,我已將其添加到自定義UIView中,隨後將其添加爲我的主視圖的子視圖。出於某種原因,當用戶第一次嘗試捏合時,捏手勢不會被檢測到,但會在任何後來的嘗試中使用。請參閱下面的代碼,用戶在用戶稍後捏住之前必須至少觸摸一次nslog才能打印出來。iOS手勢識別器僅在用戶觸摸視圖後才啓動
聲明:
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;
}
基本上,感覺就像用戶必須 「選擇」 的觀點,然後做姿態,爲了因爲它被拾起。我試圖在視圖上啓用用戶交互和/或設置第一響應者,但它仍然不起作用。如果這種觀點有效,還有其他手勢識別器在使用,但我認爲它不應該。有沒有人有任何想法?
是否有一個原因,你有沒有實際動畫的任何東西('持續時間'和'延遲都是0)使用'UIView animateWithDuration'塊? – n00bProgrammer
取消新動畫影響元素上正在進行的動畫。在這種情況下,如果檢測到捏手勢,我想要刪除正在動畫的項目。 – kilakev