【问题标题】:UIView animation doesn't work for UIViewController subclassUIView 动画不适用于 UIViewController 子类
【发布时间】:2012-02-26 21:51:10
【问题描述】:

我尝试在当前视图中添加一个子视图(这是一个 UIViewController 的子类视图,由几个 UIButtons 和 UILabels 组成),但是动画不起作用,子视图只是出现没有动画。

代码是:

[UIView beginAnimations:nil context:nil];
[UIView setAnimaitonCurve:UIViewAnimationCurveLinear]; 
[UIView setAnimationDuration:0.5f];
[UIView setAnimationTransition:transition forView:thisPersonViewController.view cache:YES];
[self.view addSubView:thisPersonViewController.view];
[UIView commitAnimations];

它只是不起作用,但是如果我将 forView 参数从 subview (thisPersonViewController.view) 更改为 self.view, self.view 确实有动画效果,这就是古玩。

我的 xcode 版本是 4.2,SDK 版本是 5.0,感谢任何提供解决方案的人!

===========以下代码运行良好===============

CATransition *trans = [CATransition animation];
[trans setDuration:0.4f];
[trans setType:kCATransitionReveal];
[trans setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[thisPersonViewController.view layer]addAnimation:trans forKey:kCATransitionReveal];
[self.view addSubview:thisPersonViewController.view];

另一个烦人的问题是,如果我将 CATransition 类型更改为 kCATransitionFromBottom 或其他动画无法再次运行!

【问题讨论】:

  • 对不起,但这根本没有意义。请仔细研究MVC 模式
  • 给你一个提示:视图不能是视图控制器的子类

标签: ios xcode uiview ios5 uiviewcontroller


【解决方案1】:
  1. 将 thisPersonViewController.view 添加为子视图,并在屏幕外的某个位置添加。 (即屏幕底部的帧 x/y 坐标。)

  2. 这样做:

[UIView animateWithDuration:0.5f delay:0.0f options:UIViewAnimationCurveLinear animations:^(void) { // Move it to wherever you want to have it. thisPersonViewController.view.frame = CGRectMake(0.0f, 0.0f, thisPersonViewController.view.frame.size.width, thisPersonViewController.view.frame.size.height); } completion:^(BOOL finished) { // Do something when it completes the animation if you so desire. }];

【讨论】:

  • 能否请您告诉我如何执行不同类型的动画,例如 UIViewAnimationTransitionCurlUp ?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-05-22
  • 1970-01-01
  • 2013-07-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多