繁体   English   中英

UIView动画无效

[英]UIView animation not working

我有以下代码来做一个UIView动画:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelegate:self];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:mapView.view cache:NO];
[self addSubview:detailView];
[mapView removeFromSuperview];
[UIView commitAnimations];

它在我不添加detailView时有效。 实际发生的事情相当于:

[self addSubview:detailView];
[mapView removeFromSuperview];

我觉得你的订单错了。 您需要先删除旧的子视图,然后再添加新的子视图。

请参阅setAnimationTransition的参考:forView:cache:

您还可以在视图层上使用CATransition。 然后使用图层动画。

如果你特意想要翻转新视图,你也可以使用uiviewcontroller的presentalModalViewController方法。

我一直在教程中看到你的代码,但从来没有对我有用。 我一直用这个:

UIViewController *mainViewController = [[YourMainViewController alloc] init];
UIViewController *viewControllerToSwitchTo = [[ViewControllerToSwitchTo alloc] init];

[mainViewController presentModalViewController:viewControllerToSwitchTo animated: YES];

您可以使用以下命令设置视图更改样式:

[setModalTransitionStyle:WhateverModalTransitionStyleYouWant];

但请确保在转换方法之前执行此操作。

该代码不起作用。 来自Apple的文档:

如果要在转换期间更改视图的外观(例如,从一个视图翻转到另一个视图),则使用容器视图(UIView的实例),如下所示:

  1. 开始动画块。
  2. 在容器视图上设置转换。
  3. 从容器视图中删除子视图。
  4. 将新子视图添加到容器视图中。
  5. 提交动画块。

所以转换应该应用于self而不是mapView,并且你的添加/删除顺序相反。

我不得不将图形上下文设置为UIGraphicsGetCurrentContext()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM