【发布时间】: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