如果没有视图更新,动画不会开始
我遇到了一个奇怪的问题。
我有基于导航的应用程序,带有两个 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
时,动画将与视图之间的自定义转换一起使用。
为什么? 有没有简单的方法来更新显示视图以启动动画?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你应该写
在 viewDidLoad 方法中。并将方法从
viewDidAppear 更改为 viewWillAppear,
将 viewDidDisappear 更改为 viewWillDisappear。
希望它会起作用...
I think you should have to write
in viewDidLoad method. and change method from
viewDidAppear to viewWillAppear and
viewDidDisappear to viewWillDisappear.
Hope It will works...
我认为你必须使用以下方法在视图上执行动画:
I think you have to perform the animations on the view using: