UIView transistionWithAnimation不起作用

所以我想学习块的过渡动画。所以我去了苹果文档,并使用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

以上是 UIView transistionWithAnimation不起作用 的全部内容, 来源链接: utcz.com/qa/259521.html

回到顶部