如果没有视图更新,动画不会开始

发布于 2024-11-15 04:08:07 字数 2732 浏览 3 评论 0原文

GitHub 上的示例

我遇到了一个奇怪的问题。

我有基于导航的应用程序,带有两个 UIViewController 和用于在它们之间进行转换的 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]! 如果没有更新屏幕,它不会启动 - 您可以单击底部的按钮并查看它!

这是错误吗?

动画无需自定义过渡即可正常工作。

当我为推送或弹出视图设置 animated:YES 时,动画将与视图之间的自定义转换一起使用。

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

Sample on GitHub

I have a strange problem.

I have Navigation-based app with two UIViewControllers and Curl effect for transition between these.

I add to bar button and add custom action:

-(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];
}

In SecondView I have a button with action:

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

Method backPage in AppDelegate:

-(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]; 
}

PROBLEM:
On the RootView I have UIImageView with animation:

- (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;
}

I start it in viewDidAppear:

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

I stop it in viewDidDisapear:

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

When I back from SecondView animation is stoped! But [animImage isAnimating] say YES!
It doesn't start witout update screen - you can click to button on the bottom and see it!

Is it bug?

Animation works without custom transitions.

When I set animated:YES for push or pop view, animation works with custom transitions between views.

Why?
Is there simple way to update displaying view to start animation?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

微凉 2024-11-22 04:08:07

我认为你应该写

 [yellowBatterfly startAnimating]; 

在 viewDidLoad 方法中。并将方法从

viewDidAppear 更改为 viewWillAppear,

将 viewDidDisappear 更改为 viewWillDisappear。

希望它会起作用...

I think you should have to write

 [yellowBatterfly startAnimating]; 

in viewDidLoad method. and change method from

viewDidAppear to viewWillAppear and

viewDidDisappear to viewWillDisappear.

Hope It will works...

青衫儰鉨ミ守葔 2024-11-22 04:08:07

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

[UIView commitAnimations]

I think you have to perform the animations on the view using:

[UIView commitAnimations]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文