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"];
謝謝Mishie。爲什麼我使用CATransitions沒有什麼特別的理由說我不知道更好。我確實嘗試過使用標準UIViews的代碼,但它仍然沒有提供所需的效果。窗口視圖確實向上滑動,但newView只出現在屏幕的頂部,在窗口視圖上方,然後滑落。我希望窗口視圖向上滑動,newView出現在底部。我如何使用標準UIView控制動畫?謝謝! – Doug
你只需要正確設置幀座標。我不確定你的newView的開始幀是什麼,所以我只是猜測=) – MishieMoo
再次感謝Mishie。這將工作。 – Doug