0

所以我想学习带有块的过渡动画。所以我去了苹果文档,并使用旧方法(无块)做了一个动画示例。我已经获取了代码片段(稍作修改)并对其进行了测试。它完美地工作

[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 上对此进行测试。但是它似乎没有动画,我不明白为什么会这样。它改变了视图,只是没有动画。请帮忙。

4

1 回答 1

0

尝试用 transitionToView:fromView 替换 transitionWithView

于 2012-01-03T19:32:14.687 回答