这是我的第一个问题,所以请温和些:我有下面的动画代码在模拟器和真实设备上流畅地运行(我在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;
}发布于 2009-12-11 12:22:17
尝试将组和/或变换动画的fillMode设置为kCAFillModeForwards:
theGroup.fillMode = kCAFillModeForwards;这将使您的动画在其活动持续时间完成后持续存在。我以前用过这个来消除动画结束的闪烁。
发布于 2009-12-11 08:49:58
我不确定我完全理解你看到的是什么,但你可能看到了一些由设备和模拟器之间的速度差异造成的东西。模拟器比设备快得多,所以“眨眼”非常快的东西可能太快了,人眼看不到模拟器。
发布于 2009-12-11 10:03:10
哇哦。这太烦人了。我认为在动画停止和这行代码执行之间会有一个瞬间。如果有一个animationWillStop:方法就好了!您可以尝试使用screenShot.alpha = 0,而不是screenShot.hidden = YES。我怀疑它在速度方面会有什么不同,但它可能值得一试?您也可以将视图作为动画的一部分淡出,但我不认为您希望这样做。
我能想到的唯一的另一件事就是在动画时间下设置一个间隔的NSTimer。类似于:
[NSTimer scheduledTimerWithTimeInterval:(ANIMATION_TIME - .001) target:self selector:@selector(hideTheView) userInfo:nil repeats:NO];当然,然后实现hideTheView方法。
https://stackoverflow.com/questions/1884705
复制相似问题