Iphone 同步UIView动画
嗨,为了响应触摸事件,我的应用程序会查看动画。如果用户真的很快,即使在当前动画正在发生的时候,也会再次触摸,那么一切都会变得一团糟 框架是否提供了处理此问题的标准方法?还是我做动画的方式不对 目前它正在检查一个标志(AnimationProgress)来处理这个问题,但我想知道这是否是我们必须求助的 代码如下:Iphone 同步UIView动画,iphone,ios,uiview,core-animation,Iphone,Ios,Uiview,Core Animation,嗨,为了响应触摸事件,我的应用程序会查看动画。如果用户真的很快,即使在当前动画正在发生的时候,也会再次触摸,那么一切都会变得一团糟 框架是否提供了处理此问题的标准方法?还是我做动画的方式不对 目前它正在检查一个标志(AnimationProgress)来处理这个问题,但我想知道这是否是我们必须求助的 代码如下: - (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void
- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
NSMutableArray *c = (NSMutableArray*)context;
UINavigationController *nc = [c objectAtIndex:0];
[nc.view removeFromSuperview];
animationInProgress = NO;
}
- (void)transitionViews:(BOOL)topToBottom {
if (animationInProgress) {
return;
}
animationInProgress = YES;
NSMutableArray *context = [[NSMutableArray alloc] init];
[UIView beginAnimations:@"myanim" context:context];
[UIView setAnimationDuration:0.7f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
UIViewController *from;
UIViewController *to;
if (navController3.view.superview == nil ) {
from = navController2;
to = navController3;
} else {
from = navController3;
to = navController2;
}
int height;
if (topToBottom) {
height = -1 * from.view.bounds.size.height;
} else {
height = from.view.bounds.size.height;
}
CGAffineTransform transform = from.view.transform;
[UIView setAnimationsEnabled:NO];
to.view.bounds = from.view.layer.bounds;
to.view.transform = CGAffineTransformTranslate(transform, 0, height);
[window addSubview:to.view];
[UIView setAnimationsEnabled:YES];
from.view.transform = CGAffineTransformTranslate(from.view.transform, 0, -1 * height);
to.view.transform = transform;
[context addObject:from];
[UIView commitAnimations];
return;
}
正如您所注意到的,框架的默认行为是,如果您愿意,允许任何事情同时发生 如果您的目标是阻止特定动画(如果该动画已在运行)的发生,那么像您正在做的那样使用标志是完全合理的 如果您想在概念上“提升一个级别”,并在动画期间阻止任何触摸事件进入您的应用程序,您可以使用:
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
与一个:
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
如果在动画期间使用begin/endIgnoringInteractionEvents阻止任何触摸事件进入应用程序,则在该块中可能出现的触摸事件会发生什么情况?一旦调用endIgnoringInteractionEvents,它们会被缓存并呈现给应用程序吗?还是会丢弃所有触摸(顾名思义)?@vance:它们会被丢弃,顾名思义。