我尝试向当前 View 添加一个 subview (它是 UIViewController 的子类 View ,由几个 UIButtons 和 UILabels 组成),但动画不起作用, subview 只是出现而没有动画。
代码是:
[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 或其他内容,动画将不再起作用!
最佳答案
将 thisPersonViewController.view 添加为 subview ,其位置位于屏幕之外。 (即屏幕底部的框架 x/y 坐标。)
这样做:
[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.
}];
关于ios - UIView 动画不适用于 UIViewController 子类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9142875/