我正在構建一個應用程序,其中第一個視圖有一個菜單面板,我希望此面板堅持應用程序的生命週期。用戶可以「去」的唯一位置可通過此面板上的按鈕(UICollectionView)進行訪問。萬一它很重要,這個應用程序是唯一的,僅iOS 6。自定義從左到右動畫對角線而不是
爲了做到這一點,我創建了一個自定義的segue,它除了菜單面板之外從視圖中移除所有東西,然後將新視圖控制器的視圖添加爲子視圖,將新視圖的框架設置爲超視圖的邊界,並將新視圖發送到後面(所以它在菜單面板後面)。我從prepareForSegue中調用viewWill/DidDisappear,否則它們不會被調用。
這可能聽起來很糟糕(它對我來說),但除了一件事情之外,它可以正常工作 - 新視圖從底部出現。它看起來很有趣。
然後我嘗試添加我自己的動畫塊 - 我最初將視圖定位到左側,然後將其動畫到位。我將它發送到動畫完成塊的後面。這看起來非常合乎邏輯,框架值完全是他們應該做的。但是這個更糟糕 - 從左下角進入視角。
任何人都可以提出一種方法來使這項工作?這是我目前的執行方法:
- (void)perform {
MainMenuViewController *sourceVC = (MainMenuViewController *)self.sourceViewController;
UIViewController *destinationVC = (UIViewController *)self.destinationViewController;
for (UIView *subview in [sourceVC.mainView subviews]) {
// don't remove the menu panel or the tab
if (![subview isKindOfClass:[UICollectionView class]] && [subview.gestureRecognizers count] == 0) {
[subview removeFromSuperview];
}
}
[sourceVC.mainView addSubview:destinationVC.view];
CGRect finalFrame = sourceVC.mainView.bounds;
CGRect frame = finalFrame;
frame.origin.x = finalFrame.origin.x - finalFrame.size.width;
destinationVC.view.frame = frame;
[UIView animateWithDuration:0.5 animations:^{
destinationVC.view.frame = finalFrame;
} completion:^(BOOL finished) {
// make sure it ends up behind the main menu panel
[sourceVC.mainView sendSubviewToBack:destinationVC.view];
}];
}