2012-02-04 61 views
0

我试图向当前视图添加一个子视图(它是一个子类UIViewController的视图,包含多个UIButtons和UILabels),但动画不起作用,子视图刚刚出现动画。UIView动画不适用于UIViewController子类

代码:

[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参数从子视图(thisPersonViewController.view)到self.view,自我。视图做动画,这是古董。

我的xcode版本为4.2,SDK版本为5.0,thx适合任何提供解决方案的人!

===========下面的代码工作正常===============

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

抱歉,但这是没有意义的。请仔细研究[MVC](https://developer.apple.com/library/ios/#documentation/General/Conceptual/DevPedia-CocoaCore/MVC.html)模式 – vikingosegundo 2012-02-04 17:39:45

+0

给你一个提示:视图不能是一个视图控制器 – vikingosegundo 2012-02-04 17:40:19

+0

的子类,听起来正确 – vikingosegundo 2012-02-04 17:46:16

回答

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. 
}]; 
 
+0

我会马上尝试,thx为您的答案 – jasonslyvia 2012-02-04 17:47:47

+0

酷!这样可行! – jasonslyvia 2012-02-04 17:49:10

+0

抱歉不能投票,但我真的很感激你的回答! – jasonslyvia 2012-02-04 17:50:15