0

这是对上一个问题的跟进(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 文档,但未能找到解决方案。感谢您的时间。

4

2 回答 2

1

摆脱形式的束缚;您需要添加UIViewAnimationOptionAllowUserInteraction到动画块中的选项。

回答您的评论问题。是的,您可以轻松地使用多个动画选项。您通常使用按位或运算符“ |”,如下所示:

[UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction animations...
于 2012-06-22T03:38:29.773 回答
0

NJones 给出了正确的答案。我只需要在我的代码UiViewAnimationOptionAllowUserInteraction选项下添加。[UIView animationWithDuration...]

于 2012-06-22T03:33:00.557 回答