【问题标题】:Flip animation is ignoring duration, i.e. I can't control speed翻转动画忽略持续时间,即我无法控制速度
【发布时间】:2011-05-24 18:27:41
【问题描述】:

所以我尝试在两张图像之间切换,但持续时间似乎被忽略了。 我知道 Apple 必须非常快地制作一些动画才能保持魔法的活力,但是有没有办法减慢翻转速度?

我当前的对象层次结构是游戏板,其中包含许多继承自 UIView 的卡片。 卡片的正面和背面是承载 UIImage 和其他数据的 UIViews

[UIView animateWithDuration:15.0 
    animations:^(void) {
        cardOne.center =CGPointMake(100, 100);
        cardTwo.center =CGPointMake(100, 100);

        //low level calls, to directly perform the image swap 
        [cardOne.face removeFromSuperview]; 
        [cardOne addSubview:cardOne.back];
        [cardOne sendSubviewToBack:cardOne.face]; 

        //calling the transitionFromView to do the image swap
        [UIView transitionFromView:cardOne.face 
                            toView:cardOne.back 
                          duration:10 
                           options:UIViewAnimationTransitionFlipFromLeft 
                        completion:^(BOOL finished){ }];

感谢您的反馈。我尝试混合您输入的所有内容,但最终确实可以正常工作。我还不知道为什么。 感谢您的回复。我尝试恢复到旧样式并且它起作用了。我还没弄明白为什么。

非工作代码被注释掉,工作代码不加注释。 再次感谢

/*  
[UIView animateWithDuration:animationDuration  
animations:^{  
    [self.face removeFromSuperview];    
    [self addSubview:self.back];  
    [self sendSubviewToBack:self.face];              
}];  
*/

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:kDefaultFlipSpeed];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
                               forView:self
                                 cache:YES];

[self.face removeFromSuperview];
[self addSubview:self.back];
[self sendSubviewToBack: self.face];

[UIView commitAnimations];

【问题讨论】:

  • 你尝试过老式的 +beginAnimations API 吗?
  • 这是不必要的 - 并且可能具有破坏性 - 复杂。尝试删除除 .center 集和 -transitionFromView:toView:duration:options:completion: call 之外的所有内容; removeFromSuperview、addSubview 和 animateWithDuration:animations: 东西是多余的,可能会干扰动画。
  • 我添加了 [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self cache:YES];进入动画块,它现在可以与新的块样式调用一起正常工作。

标签: iphone ios ipad duration flip


【解决方案1】:

我不能在评论中提问,所以: 你试过不到 10 秒吗?更准确地说是在 0-1 秒之间。大约0.5秒。如果您注意到这些值的持续时间有任何变化,请告诉我。

我的快速回答是: 尝试将 10 秒设置为 10.0 或 10.0f。

希望对你有帮助。

【讨论】:

  • 感谢您的回复。我尝试恢复到旧样式并且它起作用了。我还没弄清楚为什么。
  • 很高兴听到!我认为kDefaultFlipSpeed 成功了。如果你仍然想改变速度,试试我之前告诉你的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多