2013-04-10 48 views
1

我正在研究和iPhone應用程序,並且有手勢識別器的問題。轉換圖層上的UIGestureRecognizer

我在視圖中添加了UITapGestureRecognizer,然後使用CABasicAnimation轉換與此視圖相關的圖層。在此轉換之後,手勢識別器只能在轉換之前的視圖佔用的區域中工作。

希望我的問題,這一點說明是可以理解的..

下面是一些代碼:

UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(myViewTapped:)]; 
[self.myView addGestureRecognizer:tapGestureRecognizer]; 

CABasicAnimation * animation = [CABasicAnimation animationWithKeyPath:@"position.y"]; 
[animation setFromValue:[NSNumber numberWithFloat:0]]; 
[animation setToValue:[NSNumber numberWithFloat: - 100]]; 
[animation setDuration:.3]; 
[animation setTimingFunction:[CAMediaTimingFunction functionWithControlPoints:.55 :-0.25 :.30 :1.4]]; 
animation.additive = YES; 
animation.removedOnCompletion = NO; 
animation.fillMode = kCAFillModeForwards; 
[self.myView.layer addAnimation:animation forKey:nil]; 

我如何處理這個問題?

謝謝!

回答

1

您只對視圖的圖形部分(CALayer)進行動畫處理,而不是對用戶交互(UIView本身)負責的部分。 您的代碼移動圖層並使其在別處被淹沒,但不要更改框架(或綁定的+中心)。

你有3個選項(也可能更多,只是我能想到的這3個):

1)使用基於的UIView的動畫[UIView animation...]

2)結構與您的代碼,但也relocare視圖動畫發生後(但這可能會導致您的圖層也會移動)。

3)使用你的動畫,但把手勢識別上的父(大)視圖,然後檢查事件有...

+0

感謝你的幫助,我 不能使用基於UIView的動畫,因爲我不得不使用自定義緩動曲線(你知道一種方法來做到這一點嗎?) 我終於找到了這個解決方案: 我將ViewController設置爲CABasicAnimation的委託,刪除了additive屬性,然後在animationDidStop方法中,我添加以下代碼行: self.bottomView.layer.position = CGPointMake(self.bottomView.layer.position.x,[((NSNumber *)((CABasicAnimation *)anim).toValue)floatValue]); - 我知道如果有人有一個更好的解決方案 – hugo 2013-04-10 13:23:30