这是previous question的后续(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文档,但未能找到解决方案。谢谢你的时间。
答案 0 :(得分:1)
要使形式脱离正轨;您需要将UIViewAnimationOptionAllowUserInteraction
添加到动画块中的选项。
回答您的评论问题。是的,您可以轻松使用多个动画选项。您通常使用按位或运算符“|
”,如下所示:
[UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction animations...
答案 1 :(得分:0)
UiViewAnimationOptionAllowUserInteraction
代码的选项下添加[UIView animationWithDuration...]
。