簡體   English   中英

UIView動畫不適用於UIViewController子類

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

我嘗試向當前視圖添加一個子視圖(這是UIViewController的子類,由幾個UIButton和UILabel組成),但是動畫不起作用,該子視圖只是不帶動畫而出現。

代碼是:

[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,對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作為子視圖添加,其位置在屏幕之外。 (即,幀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.
}];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM