没有视图更新,动画无法启动

时间:2011-06-09 10:32:18

标签: iphone animation uinavigationcontroller uiimageview

Sample on GitHub

我有一个奇怪的问题。

我有基于导航的应用程序,带有两个UIViewControllers和Curl效果,用于在这些之间进行转换。

我添加到栏按钮并添加自定义操作:

-(IBAction)pushPage
{
    NSLog(@"push page");
    SecondViewController *secondView = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
    [UIView beginAnimations:@"animation" context:nil];
    [UIView setAnimationDuration:0.75];
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.navigationController.view cache:NO];
    [self.navigationController pushViewController:secondView animated:NO];
    [UIView commitAnimations];  
    [secondView release];
}

在SecondView中,我有一个带动作的按钮:

-(IBAction)back
{
    [imageAnimationIssueAppDelegate backPage];
}

AppDelegate中的方法backPage

-(void)backPage
{
    NSLog(@"backPage");
    [UIView beginAnimations:@"animation" context:nil];
    [UIView setAnimationDuration:0.75];
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.navigationController.view cache:NO];
    [self.navigationController popToRootViewControllerAnimated:NO];
    [UIView commitAnimations]; 
}

问题: 在RootView上我有UIImageView动画:

- (void)viewDidLoad
{
    [super viewDidLoad];

    animImage.animationImages = [NSArray arrayWithObjects:
                             [UIImage imageNamed:@"1.png"],
                             [UIImage imageNamed:@"2.png"],
                             [UIImage imageNamed:@"3.png"],
                             [UIImage imageNamed:@"4.png"],                                 
                             [UIImage imageNamed:@"3.png"],
                             [UIImage imageNamed:@"2.png"],
                             nil];
    animImage.animationDuration = 0.5;
    animImage.animationRepeatCount = 0;
}

我在viewDidAppear开始:

- (void)viewDidAppear:(BOOL)animated
{
    NSLog(@"First view - viewDidAppear");
    [super viewDidAppear:animated];
    [animImage startAnimating];
}

我在viewDidDisapear中停止了它:

- (void)viewDidDisappear:(BOOL)animated
{
    NSLog(@"First view - viewDidDisappear");
    [super viewDidDisappear:animated];
    [animImage stopAnimating];    
}

当我从SecondView动画回来时停止了!但是[animImage isAnimating]YES! 它无法在更新屏幕上启动 - 您可以单击底部的按钮并查看它!

是错误吗?

动画无需自定义过渡即可运行。

当我为推送或弹出视图设置animated:YES时,动画可以在视图之间自定义转换。

为什么吗 有没有简单的方法来更新显示视图以开始动画?

2 个答案:

答案 0 :(得分:1)

我认为你应该写

 [yellowBatterfly startAnimating]; 

在viewDidLoad方法中。并改变方法

viewDidAppear to viewWillAppear和

viewDidDisappear to viewWillDisappear。

希望它会起作用......

答案 1 :(得分:0)

我认为你必须使用以下方法在视图上执行动画:

[UIView commitAnimations]