簡體   English   中英

UIView動畫無效

[英]UIView animation not working

我有以下代碼來做一個UIView動畫:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelegate:self];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:mapView.view cache:NO];
[self addSubview:detailView];
[mapView removeFromSuperview];
[UIView commitAnimations];

它在我不添加detailView時有效。 實際發生的事情相當於:

[self addSubview:detailView];
[mapView removeFromSuperview];

我覺得你的訂單錯了。 您需要先刪除舊的子視圖,然后再添加新的子視圖。

請參閱setAnimationTransition的參考:forView:cache:

您還可以在視圖層上使用CATransition。 然后使用圖層動畫。

如果你特意想要翻轉新視圖,你也可以使用uiviewcontroller的presentalModalViewController方法。

我一直在教程中看到你的代碼,但從來沒有對我有用。 我一直用這個:

UIViewController *mainViewController = [[YourMainViewController alloc] init];
UIViewController *viewControllerToSwitchTo = [[ViewControllerToSwitchTo alloc] init];

[mainViewController presentModalViewController:viewControllerToSwitchTo animated: YES];

您可以使用以下命令設置視圖更改樣式:

[setModalTransitionStyle:WhateverModalTransitionStyleYouWant];

但請確保在轉換方法之前執行此操作。

該代碼不起作用。 來自Apple的文檔:

如果要在轉換期間更改視圖的外觀(例如,從一個視圖翻轉到另一個視圖),則使用容器視圖(UIView的實例),如下所示:

  1. 開始動畫塊。
  2. 在容器視圖上設置轉換。
  3. 從容器視圖中刪除子視圖。
  4. 將新子視圖添加到容器視圖中。
  5. 提交動畫塊。

所以轉換應該應用於self而不是mapView,並且你的添加/刪除順序相反。

我不得不將圖形上下文設置為UIGraphicsGetCurrentContext()

暫無
暫無

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

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