是否有任何方式以編程方式隱藏splitviewcontroller中的主視圖。在我的應用程序中,第一個屏幕將是一個splitviewcontroller,我不需要爲下一個屏幕分割視圖。我可以如何實現這一點如何在UiSplitviewcontroller中隱藏iPad中的主視圖
回答
測試馬特Gemmell創建一個名爲 「MGSplitViewController」 一個優秀的定製splitViewController。它非常容易實現,經過嚴格評論,並且包含許多優秀的功能,這些功能在普通的splitViewController中沒有找到(在橫向視圖中隱藏主視圖,在橫向視圖中更改分割位置,允許用戶在運行時更改流暢分割的大小,等等)。
信息和演示:http://mattgemmell.com/2010/08/03/mgsplitviewcontroller-updated/
用Xcode 6和iOS 8構建時要小心......看起來會炸燬構架 – whyoz 2014-11-10 19:03:28
雖然它不會有很好的轉換(對不起),但可以通過將根視圖設置爲詳細視圖控制器的視圖,然後使用UISplitView交換視圖並將詳細視圖移動到UISplitView。 (實際上,您可能可以爲視圖交換(推/翻頁等)設置動畫效果,但在視圖更改動畫期間更改任何內容是個不錯的主意,並且將詳細視圖移動到UISplitView的內部可能符合要求。)
不知道這是你想要的。舉例來說,隱藏母版視圖在橫向模式下,當按鈕被點擊,你可以做以下(在選擇方法)
UIViewController *master = [splitViewController.viewControllers objectAtIndex:0];
UIViewController *detail = [splitViewController.viewControllers objectAtIndex:1];
[master.view setFrame:CGRectMake(0, 0, 0, 0)];
detail.view.frame = splitViewController.view.bounds; // or use master and detail length
試試這個:
splitVC.modalPresentationStyle = UIModalPresentationFullScreen;
[splitVC presentModalViewController:[[splitVC viewControllers] objectAtIndex:1] animated:NO];
在4.2對我的作品!
這是另一個可行的技巧。 video link在這裏。
在SDK 5.0中,他們爲UISplitViewControllerDelegate添加了新的方法,可以輕鬆爲您做到這一點。只是實現它像旁邊,你不會看到主視圖:
- (BOOL)splitViewController:(UISplitViewController*)svc
shouldHideViewController:(UIViewController *)vc
inOrientation:(UIInterfaceOrientation)orientation
{
return YES;
}
時,你可以看到它的唯一的地方是旋轉 - 母版視圖的一部分動畫過程中是可見的。我已經用簡單的方法解決了這個問題,只是在master中加載空白和黑色視圖。
PS:不確定這是否是真實的i0707。但希望這對於現在有相同問題的其他人有用。
這工作:
附加「隱藏」的方法,以您的按鈕,例如:
UIBarButtonItem *hideButton = [[UIBarButtonItem alloc] initWithTitle:@"hide"
style: UIBarButtonItemStylePlain
target: self
action: @selector(hide:)
];
[self.mainView.navigationItem setLeftBarButtonItem:hideButton];
在該代碼中,「self.mainView」是在導航控制器視圖控制器splitview的第二個視圖 - 僅供參考。
hide方法看起來像這樣。
-(void)hide:(id)sender
{
UIViewController *masterController = [self.viewControllers objectAtIndex:0];
CGRect selfFrame = self.view.frame;
CGFloat aWidth = masterController.view.frame.size.width;
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.30f];
if(orientation == UIDeviceOrientationLandscapeLeft)
{
selfFrame.size.height += aWidth;
selfFrame.origin.y -= aWidth;
}
else if(orientation == UIDeviceOrientationLandscapeRight)
{
selfFrame.size.height += aWidth;
}
[self.view setFrame:selfFrame];
[UIView commitAnimations];
}
這是出發點,顯然更多的邏輯需要做照顧旋轉,再次展示了它,等...
我希望這有助於。
與iOS5的和Xcode的4.3
對我不起作用 – kinghomer 2012-10-19 11:34:30
上面我沒有工作的代碼,但是,當我試圖
CGRect selfFrame = self.splitViewController.view.frame;
它沒有。所以....這對我的作品。(此代碼應該在你detailviewcontroller)
-(void)hideMaster {
UIViewController *masterController = GetAppDelegate().masterController;
CGRect selfFrame = self.splitViewController.view.frame;
CGFloat aWidth = masterController.view.frame.size.width;
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.30f];
if(orientation == UIDeviceOrientationLandscapeLeft)
{
selfFrame.size.height += aWidth;
selfFrame.origin.y -= aWidth;
}
else if(orientation == UIDeviceOrientationLandscapeRight)
{
selfFrame.size.height += aWidth;
}
[self.splitViewController.view setFrame:selfFrame];
[UIView commitAnimations];
}
爲了讓這個需要旋轉:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation duration:(NSTimeInterval)duration
{
[super willAnimateRotationToInterfaceOrientation:interfaceOrientation duration:duration]; // not sure if needed
//By the time this method is called the bounds of the view have been changed
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
if (UIInterfaceOrientationIsPortrait(interfaceOrientation)) {
if (masterIsHidden) {
[self showMaster];
}
} else {
if (self.editing) {
[self hideMaster];
}
}
[UIView setAnimationDuration:duration];
[UIView commitAnimations];
}
對我不起作用 – kinghomer 2012-10-19 11:56:08
這對我很好用。輸入editMode時,我在詳細視圖中使用它。我創建了一個showMaster方法,將主寬度保存在iVar中,然後在hideMaster中反轉+ =和 - +符號。我的實現還使用masterIsHidden iVar來防止隱藏已隱藏的視圖。 – 2014-06-04 16:36:57
由SplitViewController提供的BarButtonItem是關鍵以編程方式隱藏主視圖控制器。
此代碼是危險的!但優雅:)
導入目標C消息庫
#import <objc/message.h>
下,得到一個處理當事件被觸發由SplitViewController提供
- (void)splitViewController:(UISplitViewController *)splitController willHideViewController:(UIViewController *)viewController withBarButtonItem:(UIBarButtonItem *)barButtonItem
forPopoverController:(UIPopoverController *)popoverController
{
barButtonItem.title = @"Master";
[self.navigationItem setLeftBarButtonItem:barButtonItem animated:YES];
//Obtain handle to BarButtonItem
[self setMasterButtonItem:barButtonItem];
}
那麼的UIBarButtonItem應該觸發自動解除主視圖控制器即
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
你可以做到這一點
objc_msgSend(self.masterButtonItem.target, self.masterButtonItem.action);
這實際上是一個很好的解決方案,與其他一些想法相比,應該是相對「安全」的。你甚至可以跳過'objc_msgSend()'並且調用'[[UIApplication sharedApplication] sendAction:masterBarButtonItem.action::masterBarButtonItem.target from:nil forEvent:nil]'。 – jrc 2013-03-15 19:09:05
同傑克的答案,但一個班輪。過去到 - (void)setDetailItem:(id)newDetailItem {...}來解散主。
[[UIApplication sharedApplication] sendAction: self.navigationItem.leftBarButtonItem.action
to: self.navigationItem.leftBarButtonItem.target
from: nil
forEvent: nil];
- 1. 防止隱藏UISplitViewController主視圖(iPad iOS 4.x)
- 2. UISplitViewController - 隱藏主幻燈片視圖
- 3. 只有某些視圖隱藏主UISplitViewController
- 4. 在iOS 8的UISplitViewController中動畫顯示/隱藏主視圖
- 5. 在iOS8中使用UISplitViewController隱藏主視圖控制器
- 6. 如何取消隱藏UISplitViewController的主人?
- 7. UISplitViewController - 主視圖在縱向模式下隱藏時的事件?
- 8. iPad UISplitViewController幻影主視圖控制器
- 9. 如何隱藏IOSIS中的UISplitViewcontroller的masterView
- 10. 如何在iPad上使用UIContainerView隱藏UISplitViewController主內嵌輔助UITableViewController的DetailView
- 11. UISplitViewController:旋轉後隱藏的主視圖導航欄
- 12. Monotouch UISplitViewController隱藏主視圖像郵件應用程序
- 13. 顯示/隱藏UISplitViewController的主視圖控制器轉移詳細視圖
- 14. iPad UISplitViewController視圖框架
- 15. iPad UISplitViewController多根視圖
- 16. UISplitViewController displayModeButtonItem在iPAD中
- 17. 如何在UISplitViewController的主視圖中添加標籤欄
- 18. 如何在MVC視圖中隱藏div?
- 19. 如何在RecyclerView中隱藏視圖
- 20. android,SlidingPaneLayout,隱藏主視圖
- 21. 在分割視圖應用中隱藏主視圖..?
- 22. ipad旋轉隱藏在視圖中的元素!
- 23. ModalViewController隱藏在視圖中
- 24. MVC局部視圖隱藏主視圖
- 25. 如何以編程方式隱藏UISplitViewController的主部分?
- 26. 如何隱藏iPad中的軟鍵盤
- 27. 具有多個視圖的iPad UISplitViewController
- 28. iPad的uisplitviewcontroller左視圖成爲balck
- 29. 在ConstraintLayout中隱藏從屬視圖時隱藏視圖
- 30. 隱藏UISplitViewController中的縱向覆蓋
當你說隱藏masterview,你的意思是在SplitViewController的左邊創建一個空白的視圖,或者你的意思是讓DetailViewController在橫向模式下填充100%的屏幕? – 2010-04-23 17:11:32
第二種選擇是讓DetailViewController以任一模式(橫向或縱向)填充屏幕的100%。 – i0707 2010-04-26 06:48:03
任何解決方案呢?我正在嘗試做同樣的事情,我嘗試以模態形式呈現,如: – 2011-01-21 07:06:30