ios - UIView 动画不适用于 UIViewController 子类

标签 ios xcode uiview ios5 uiviewcontroller

我尝试向当前 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 或其他内容,动画将不再起作用!

最佳答案

  1. 将 thisPersonViewController.view 添加为 subview ,其位置位于屏幕之外。 (即屏幕底部的框架 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.
}];

关于ios - UIView 动画不适用于 UIViewController 子类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9142875/

相关文章:

ios - JSON key :value pairs disappearing after original json call

ios - 使用 Realm 对象保存用户

xcode - 使用 Xcode 4 创建 MacOS 服务

xcode - 如何在 Xcode 4 中使用 dylib 文件创建工作框架

swift - 加载 Controller 后如何以编程方式添加 View

iphone - 大型自定义 UIView - CABackingStoreUpdate 性能

ios - AdMob 原生广告

iOS - 嵌套的 ScrollView 并将手势传递给同级 subview

android - 使用 Amazon SNS 服务发送推送通知

ios - 在 2 个 View Controller 上显示 View