0

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.

Community
  • 1
  • 1
Maximilian
  • 1,107
  • 11
  • 20
  • 1
    Have you tried the `UIView` animation option `UIViewAnimationOptionAllowUserInteraction`? – NJones Jun 22 '12 at 03:12
  • NJones! Thank you! That did the trick! Though, a quick question, is there anyway to have multiple options while doing the animation? – Maximilian Jun 22 '12 at 03:31
  • 1
    Glad to help. Yes you can use more than one. I have added an answer to show how. – NJones Jun 22 '12 at 03:39

2 Answers2

1

To get the formality out of the way; You need to add UIViewAnimationOptionAllowUserInteraction to the options in your animation block.

To answer your comment question. Yes you can rather easily use more than one animation option. You generally use the bitwise or operator "|", like so:

[UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction animations...
NJones
  • 27,139
  • 8
  • 70
  • 88
0

NJones had the correct answer. I simply needed to add UiViewAnimationOptionAllowUserInteraction under the options of my [UIView animationWithDuration...] code.

Maximilian
  • 1,107
  • 11
  • 20