5

我想讓UIView向上滑動頁面的四分之一以顯示其下的另一個視圖(以顯示選項),然後向下滑動以覆蓋這些選項。我一直在不懈地搜索,但似乎無法找到我要找的東西。我不想使用模態視圖,因爲我想保持屏幕上的頂視圖。在下面的代碼中,我有它的工作,最高層級滑落,但後來完全消失(淡入淡出)。使用kCATransitionPush向上滑動UIView

任何幫助,非常感謝!

謝謝。

HomeOptionsViewController *homeOptionsViewController = [[HomeOptionsViewController alloc] 
         initWithNibName:@"HomeOptionsViewController" 
         bundle:nil]; 
// get the view that's currently showing 
UIView *currentView = self.view; 
// get the the underlying UIWindow, or the view containing the current view 
UIView *theWindow = [currentView superview]; 

UIView *newView = homeOptionsViewController.view; 
//newView.frame = CGRectMake(0,300, 320,140); 
    newView.frame = CGRectMake(0,-10, 320,140); 
// remove the current view and replace with myView1 
//---[currentView removeFromSuperview]; 
[theWindow addSubview:newView]; 

theWindow.frame = CGRectMake(0,-110,320,200); 

newView.frame = theWindow.bounds; 
// set up an animation for the transition between the views 

CATransition *animation = [CATransition animation]; 
[animation setDuration:0.5]; 
[animation setType:kCATransitionPush]; 
[animation setSubtype:kCATransitionFromTop]; 
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; 
//[theWindow setFrame:CGRectMake(0,200,320,300)]; 
[[theWindow layer] addAnimation:animation forKey:@"SwitchToView1"]; 

回答

3

爲什麼你不使用標準UIView動畫的任何原因? CATransitions將完全改變視圖,因爲它應該是從一個視圖到另一個視圖的過渡。

你試過類似的東西嗎?您只需添加要滑動到屏幕底部的視圖,然後爲兩個幀改變動畫。它創建了一個向上滑動的效果。

newView.frame = CGRectMake(0,416,320,140); 
[theWindow addSubview:newView]; 
[UIView beginAnimations:@"SwitchToView1" context:nil]; 
[UIView setAnimationDuration:0.5]; 
theWindow.frame = CGRectOffset(theWindow.frame, 0, -140); 
newView.frame = CGRectOffset(newView.frame, 0, -140); 
[UIView commitAnimations]; 
+0

謝謝Mishie。爲什麼我使用CATransitions沒有什麼特別的理由說我不知道​​更好。我確實嘗試過使用標準UIViews的代碼,但它仍然沒有提供所需的效果。窗口視圖確實向上滑動,但newView只出現在屏幕的頂部,在窗口視圖上方,然後滑落。我希望窗口視圖向上滑動,newView出現在底部。我如何使用標準UIView控制動畫?謝謝! – Doug

+0

你只需要正確設置幀座標。我不確定你的newView的開始幀是什麼,所以我只是猜測=) – MishieMoo

+0

再次感謝Mishie。這將工作。 – Doug