This is a followup from a previous question (which was resolved beautifully by Michael Frederick).
I am currently debugging between a iOS5 device and an iOS4 device. Essentially I have a UIImage which is animating a swipe to instruct the user to swipe to continue. The animation code is as follows:
[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];
}];
}];
and the timer selector:
-(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;
}];
}];
}
This works completely fine. However, on iOS4, swipe gestures seem to be disabled; I am unable to swipe to continue as I am able to on iOS5. The only theory I have is that having the timer run on the main thread somehow disables the gesture recognizer (which I presume is sensing touch on the main thread as well). My only issue is that I have attempted to put this animation in the background as follows:
[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];
}];
}];
and the new thread selector:
-(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];
}
The animation is in place, but yet again, it seems to disable any swipe gesture recognition. I have mulled over SO, my O'Reilly materials, and the Apple documentation and have not been able to find a solution. Thank you for your time.