首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SImulator vs真实设备的iPhone动画问题

SImulator vs真实设备的iPhone动画问题
EN

Stack Overflow用户
提问于 2009-12-11 07:00:38
回答 3查看 1.7K关注 0票数 2

这是我的第一个问题,所以请温和些:我有下面的动画代码在模拟器和真实设备上流畅地运行(我在iPhone 3GS 3.1.2上测试)。动画是两个视图之间的简单过渡,有点像翻书。

模拟器和真实设备之间的一个不同之处在于,在真实设备上,当动画完成后,动画视图在隐藏之前会闪烁一段时间(显示几秒钟)。在模拟器上,这种“意想不到的”闪烁不会发生。

以下是动画代码:

代码语言:javascript
复制
-(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;

}
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2009-12-11 12:22:17

尝试将组和/或变换动画的fillMode设置为kCAFillModeForwards:

代码语言:javascript
复制
theGroup.fillMode = kCAFillModeForwards;

这将使您的动画在其活动持续时间完成后持续存在。我以前用过这个来消除动画结束的闪烁。

票数 5
EN

Stack Overflow用户

发布于 2009-12-11 08:49:58

我不确定我完全理解你看到的是什么,但你可能看到了一些由设备和模拟器之间的速度差异造成的东西。模拟器比设备快得多,所以“眨眼”非常快的东西可能太快了,人眼看不到模拟器。

票数 0
EN

Stack Overflow用户

发布于 2009-12-11 10:03:10

哇哦。这太烦人了。我认为在动画停止和这行代码执行之间会有一个瞬间。如果有一个animationWillStop:方法就好了!您可以尝试使用screenShot.alpha = 0,而不是screenShot.hidden = YES。我怀疑它在速度方面会有什么不同,但它可能值得一试?您也可以将视图作为动画的一部分淡出,但我不认为您希望这样做。

我能想到的唯一的另一件事就是在动画时间下设置一个间隔的NSTimer。类似于:

代码语言:javascript
复制
[NSTimer scheduledTimerWithTimeInterval:(ANIMATION_TIME - .001) target:self selector:@selector(hideTheView) userInfo:nil repeats:NO];

当然,然后实现hideTheView方法。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1884705

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档