• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

UIView transistionWithAnimation不起作用

IOS 来源:fzaziz 3次浏览

所以我想学习块的过渡动画。所以我去了苹果文档,并使用old method (without blocks)举了一个动画的例子。我已经采取了代码片段(稍作修改)并对其进行了测试。它完美UIView transistionWithAnimation不起作用

[UIView setAnimationDelegate:nil]; 
[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationDuration:kTransitionDuration]; 
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight 
           forView:self.view 
           cache:YES]; 

if ([self.instructionsView superview]) { 
    [self.instructionsView removeFromSuperview]; 
    [self.view addSubview:contentView]; 
} else { 
    [self.contentView removeFromSuperview]; 
    [self.view addSubview:instructionsView]; 
} 

[UIView commitAnimations]; 

// adjust our done/info buttons accordingly 
if ([instructionsView superview]) { 
    self.navigationItem.rightBarButtonItem = doneButton; 
} else { 
    self.navigationItem.rightBarButtonItem = flipButton; 
} 

现在下面的代码是我尝试将代码转换在上面的代码块

[UIView transitionWithView:self.view duration:kTransitionDuration options:UIViewAnimationTransitionFlipFromRight animations:^{ 
     if ([self.instructionsView superview]) { 
      [self.instructionsView removeFromSuperview]; 
      [self.view addSubview:contentView]; 
     } else { 
      [self.contentView removeFromSuperview]; 
      [self.view addSubview:instructionsView]; 
     } 
} completion:^(BOOL finished){ 

     if ([instructionsView superview]) { 
      self.navigationItem.rightBarButtonItem = doneButton; 
     } else { 
      self.navigationItem.rightBarButtonItem = flipButton; 
     } 
}]; 

从我所了解的是,下面的代码应该工作。我在支持块的iOS 4.2上测试这个。然而,它似乎没有动画,我不明白这是为什么。它改变了观点,只是不动画。请帮忙。

===========解决方案如下:

尝试用transitionToView替换transitionWithView:fromView


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)