简体   繁体   English

UIView动画不适用于UIViewController子类

[英]UIView animation doesn't work for UIViewController subclass

I try to add a subview(which is a subclassed UIViewController's view, consists of several UIButtons and UILabels) to current view, but the animation doesn't work, the subview just appeared without animation. 我尝试向当前视图添加一个子视图(这是UIViewController的子类,由几个UIButton和UILabel组成),但是动画不起作用,该子视图只是不带动画而出现。

the code is : 代码是:

[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];

it just doesn't work, but if I change forView parameter from the subview (thisPersonViewController.view) to self.view , the self.view did animate, that's curios. 它只是不工作,但如果我改变forView参数从子视图 (thisPersonViewController.view),以self.view,对self.view没有动画,这是古玩。

My xcode version is 4.2 and SDK version is 5.0, thx for anyone who offer an solution! 我的xcode版本是4.2,SDK版本是5.0,任何提供解决方案的人都可以使用!

===========THE FOLLOWING CODE WORKS FINE=============== ===========下面的代码很不错================

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];

Another annoying question is if I change the CATransition type to kCATransitionFromBottom or something else the animation doesn't work again ! 另一个烦人的问题是,如果我将CATransition类型更改为kCATransitionFromBottom或其他原因,动画将不再起作用!

  1. Add thisPersonViewController.view as a subview with a position somewhere off the screen. 将thisPersonViewController.view作为子视图添加,其位置在屏幕之外。 (ie frame x/y coordinate right at the bottom of the screen.) (即,帧x / y坐标位于屏幕底部的右侧。)

  2. Do this: 做这个:


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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM