質問

ジェスチャー認識者とアニメーションのUIViewクラスのメソッドに既知の問題はありますか?

uigesturerecognizerコールバックからのuiimageViewのアニメーションのシーケンスに問題があります。アニメーションのシーケンスがTouchupinsideのような標準コールバックから開始された場合、アニメーションは正常に機能します。 Uilongpressgesturerecognizerを介して開始されると、最初のアニメーションが端にジャンプし、2番目のアニメーションがすぐに開始されます。

これが私の問題を示すサンプルです。プロジェクトの.xibでは、viewtomove iboutletに接続されているuiimageviewがあります。また、StartButton Iboutletに接続されたuibuttonもあり、そのタッチピンサイドアクションをStartButtonClicked iBactionに接続しています。 Touchupinsideアクションは私が望むように機能しますが、longpressgesturerecognizerは約0.5秒後に最初のアニメーションの終わりまでスキップします。 2番目のアニメーション(Animateto200)をnslogすると、ロングプレスがアニメーションを開始するときに2回呼び出されますが、ボタンのタッチピンサイドアクションがアニメーションを開始したときにのみ1回呼び出されます。

- (void)viewDidLoad {
[super viewDidLoad];

UILongPressGestureRecognizer *longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(startButtonClicked)];
NSArray *recognizerArray = [[NSArray alloc] initWithObjects:longPressRecognizer, nil];
[startButton setGestureRecognizers:recognizerArray];

[longPressRecognizer release];
[recognizerArray release];
}

-(IBAction)startButtonClicked {

if (viewToMove.center.x < 150) {
    [self animateTo200:@"Right to left" finished:nil context:nil];
} else {
    [self animateTo100:@"Right to left" finished:nil context:nil];
}
}

-(void)animateTo100:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
[UIView beginAnimations:@"Right to left" context:nil];
[UIView setAnimationDuration:4];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animateTo200:finished:context:)];
viewToMove.center = CGPointMake(100.0, 100.0);
[UIView commitAnimations];          
}

-(void)animateTo200:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
[UIView beginAnimations:@"Left to right" context:nil];
[UIView setAnimationDuration:4];
viewToMove.center = CGPointMake(200.0, 200.0);
[UIView commitAnimations];          
}
役に立ちましたか?

解決

の署名を変更する必要があります startButtonClicked- (void)startButtonClicked:(UIGestureRegognizer *)gestureRecognizer そして、ジェスチャー認識者のクエリを照会します state メソッドのプロパティ。ジェスチャー認識者は、異なる状態でそのアクション方法を複数回呼び出します(例: UIGestureRecognizerStateBeganUIGestureRecognizerStateEnded).

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top