1

我目前正在阅读 ios6 编程初学者指南。直到刚才我尝试在两个视图之间来回切换动画时都很好。练习的最终目标是让每个视图看起来都在另一个视图的背面(就像一枚硬币/一张纸的侧面)。

然而,当我使用书中给出的代码时,只有一个动画被激活,但书中说代码应该适用于两者。

我已经多次检查我的代码,以确保我做对了,我无法区分我拥有的代码和书中的代码之间的区别。我知道我正在做的事情很简单(或者更有可能没有做),但我只是没有找到它的经验。

任何帮助将不胜感激。

代码:

- (IBAction)switchViews:(id)sender
{
[UIView beginAnimations:@"View Flip" context:nil];
[UIView setAnimationDuration:1.25];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

if (self.yellowViewController.view.superview == nil) {
    if (self.yellowViewController == nil) {
        self.yellowViewController = [[BIDYellowViewController alloc] initWithNibName:@"YellowView" bundle:nil];
    }

    // This one doesn't work
    [UIView setAnimationTransition:UIViewAnimationOptionTransitionFlipFromRight forView:self.view cache:YES];

    [self.blueViewController.view removeFromSuperview];
    [self.view insertSubview:self.yellowViewController.view atIndex:0];
}
else 
{
    if (self.blueViewController == nil) {
        self.blueViewController = [[BIDBlueViewController alloc] initWithNibName:@"BlueView" bundle:nil];
    }

    // This one works
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];

    [self.yellowViewController.view removeFromSuperview];
    [self.view insertSubview:self.blueViewController.view atIndex:0];
}
[UIView commitAnimations];
}
4

1 回答 1

2

这是因为您使用UIViewAnimationOptionTransitionFlipFromRight而不是UIViewAnimationTransitionFlipFromRight

于 2013-02-11T14:47:29.253 回答