これは、前の質問(Michael Frederickによって美しく解決された)からのフォローアップです。
私は現在、iOS5デバイスとiOS4デバイスの間でデバッグしています。基本的に、スワイプをアニメーション化してユーザーにスワイプして続行するように指示するUIImageがあります。アニメーションコードは次のとおりです。
[UIView animateWithDuration:1.0 animations:^ {
self.finger.alpha = 1.0;
}completion:^(BOOL finished) {
CGAffineTransform originalTransform = self.finger.transform;
[UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationCurveEaseInOut animations:^ {
self.finger.transform = CGAffineTransformMakeTranslation(-200, 0);
self.finger.alpha = 0.0;
}completion:^(BOOL finished) {
self.finger.transform = originalTransform;
NSTimer *timer = [NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(repeatSwipeAnimation1) userInfo:nil repeats:YES];
self.swipeTimerForFinger1 = timer;
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
[runLoop addTimer:self.swipeTimerForFinger1 forMode:NSDefaultRunLoopMode];
[self.swipeTimerForFinger1 fire];
}];
}];
およびタイマーセレクター:
-(void)repeatSwipeAnimation1 {
[UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationCurveEaseIn animations:^ {
self.finger.alpha = 1.0;
}completion:^(BOOL finished) {
CGAffineTransform originalTransform = self.finger.transform;
[UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationCurveEaseInOut animations:^ {
self.finger.transform = CGAffineTransformMakeTranslation(-200, 0);
self.finger.alpha = 0.0;
}completion:^(BOOL finished) {
self.finger.transform = originalTransform;
}];
}];
}
これは完全に正常に機能します。ただし、iOS4では、スワイプジェスチャが無効になっているようです。iOS5でできるので、スワイプして続行できません。私が持っている唯一の理論は、メインスレッドでタイマーを実行すると、ジェスチャレコグナイザーが無効になるというものです(メインスレッドへのタッチも検出していると思います)。私の唯一の問題は、次のようにこのアニメーションをバックグラウンドに配置しようとしたことです。
[UIView animateWithDuration:1.0 animations:^ {
self.finger.alpha = 1.0;
}completion:^(BOOL finished) {
CGAffineTransform originalTransform = self.finger.transform;
[UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationCurveEaseInOut animations:^ {
self.finger.transform = CGAffineTransformMakeTranslation(-200, 0);
self.finger.alpha = 0.0;
}completion:^(BOOL finished) {
self.finger.transform = originalTransform;
[NSThread detachNewThreadSelector:@selector(goToNewThread) toTarget:self withObject:nil];
}];
}];
および新しいスレッドセレクター:
-(void)goToNewThread {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSTimer *timer = [NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(repeatSwipeAnimation1) userInfo:nil repeats:YES];
self.swipeTimerForFinger1 = timer;
[[NSRunLoop currentRunLoop] addTimer:self.swipeTimerForFinger1 forMode:NSDefaultRunLoopMode];
[[NSRunLoop currentRunLoop] run];
[self.swipeTimerForFinger1 fire];
[pool release];
}
アニメーションは適切に配置されていますが、スワイプジェスチャ認識が無効になっているようです。私はSO、O'Reillyの資料、およびAppleのドキュメントを熟考しましたが、解決策を見つけることができませんでした。お時間をいただきありがとうございます。