这是我的第一个问题,所以请保持温柔: 我有跟随动画代码在模拟器和真实设备上顺利运行(我在iPhone 3GS 3.1.2上测试)。 动画是两个视图之间的简单过渡,就像书页翻页一样。
模拟器与真实设备之间的差异(我无法研究的问题 - 解决)是在动画完成时在真实设备上的一个差异 - 旋转完成之后动画视图闪烁(显示一秒钟的分割)片刻之前隐。在模拟器上,这种“意外”的眨眼不会发生。
这是动画代码:
-(void)flip{
UIView *animatedView;
// create an animation to hold the page turning
CABasicAnimation *transformAnimation = [CABasicAnimation animationWithKeyPath:@"transform"];
transformAnimation.removedOnCompletion = NO;
transformAnimation.delegate = self;
transformAnimation.duration = ANIMATION_TIME;
transformAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
// this is the basic rotation by 90 degree along the y-axis
CATransform3D endTransform = CATransform3DMakeRotation(3.141f/2.0f,
0.0f,
-1.0f,
0.0f);
// these values control the 3D projection outlook
endTransform.m34 = 0.001f;
endTransform.m14 = -0.0015f;
// start the animation from the current state
transformAnimation.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
transformAnimation.toValue = [NSValue valueWithCATransform3D:endTransform];
animatedView = screenShot;
// Create an animation group to hold the rotation and possibly more complex animation in the future
CAAnimationGroup *theGroup = [CAAnimationGroup animation];
// Set self as the delegate to receive notification when the animation finishes
theGroup.delegate = self;
theGroup.duration = ANIMATION_TIME;
// CAAnimation-objects support arbitrary Key-Value pairs, we add the UIView tag
// to identify the animation later when it finishes
[theGroup setValue:[NSNumber numberWithInt:animatedView.tag] forKey:@"animated"];
// Here you could add other animations to the array
theGroup.animations = [NSArray arrayWithObjects:transformAnimation,nil];
theGroup.removedOnCompletion = NO;
// Add the animation group to the layer
if (animatedView.layer.anchorPoint.x != 0.0f)
{
animatedView.layer.anchorPoint = CGPointMake(0.0f, 0.5f);
float yy = animatedView.center.x - (animatedView.bounds.size.width / 2.0f);
animatedView.center = CGPointMake(yy, animatedView.center.y);
}
if(![animatedView isDescendantOfView:self.view])[self.view addSubview:animatedView];
screenShot.hidden = NO;
animatedView.hidden = NO;
[animatedView.layer addAnimation:theGroup forKey:@"flip"];
}
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag {
screenShot.hidden = YES;
}
答案 0 :(得分:5)
尝试将Group和/或transformAnimation的fillMode设置为kCAFillModeForwards:
theGroup.fillMode = kCAFillModeForwards;
这会导致动画在其活动持续时间结束后仍然存在。我之前用它来消除动画结束的闪烁。
答案 1 :(得分:0)
我不确定我完全理解您所看到的内容,但您可能会看到由设备和模拟器之间的速度差异引起的某些事情。模拟器比设备快得多,因此非常快速地“闪烁”的东西可能太快,人眼无法捕捉模拟器。
答案 2 :(得分:0)
OOF。那很烦人。我认为,当动画停止和执行该行代码之间存在分秒。如果只有animationWillStop:
方法!您可以尝试,而不是screenShot.hidden = YES
,screenShot.alpha = 0
。我怀疑它在速度方面会有什么不同,但它可能值得一试?您也可以将视图淡出作为动画的一部分,但我认为您不想这样做。
我唯一能想到的是设置一个NSTimer
,其间隔时间恰好在你的动画时间之下。类似的东西:
[NSTimer scheduledTimerWithTimeInterval:(ANIMATION_TIME - .001) target:self selector:@selector(hideTheView) userInfo:nil repeats:NO];
然后实现hideTheView
方法。