簡體   English   中英

自定義呈現的UIViewController更改為全屏

[英]Custom presented UIViewController changing to fullscreen

我有一個使用UIModalPresentationCustom演示風格呈現的視圖控制器。 我使用自定義UIViewControllerTransitioningDelegate將視圖控制器顯示為側邊欄(因此它從屏幕邊緣滑入並且不占據整個屏幕)。

然而,當我然后使用UIModalPresentationFullScreen呈現另一個視圖控制器 - 然后關閉全屏視圖控制器時,我的基礎自定義顯示控制器突然調整大小以占據整個屏幕。 有誰知道為什么會這樣?

編輯:這實際上是我用於呈現側邊欄的animateTransition方法 - 我已經刪除了大部分代碼以使其可讀。 基本上它從transitionContext獲取容器,添加目標視圖控制器的視圖並將其設置為容器動畫。

- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
    UIView *container = transitionContext.containerView;

    UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    UIView *fromView = fromVC.view;
    UIView *toView = toVC.view;

    if( toVC.isBeingPresented )
    {
        [container addSubview:toView];

        //... Animate some new frame for toView            

        //Call [transitionContext completeTransition:YES] on animation completion
    }
    else
    {
        //... Animate fromView out

        //On completion remove fromView from superview

        //Call [transitionContext completeTransition:YES] on animation completion
    }
}

編輯2:做一些研究,我注意到我的自定義呈現視圖控制器的視圖的框架正在設置當模態堆棧中它上面的視圖控制器被解除時。 以下堆棧跟蹤導致框架設置為全屏:

0 -[MyCustomPresentedViewControllerView setFrame:]
1 -[UIView(MPAdditions) setFrameOrigin:]
2 -[UIViewControllerAccessibility(SafeCategory) dismissViewControllerWithTransition:completion:]
3 -[UIViewController dismissViewControllerAnimated:completion:]

通過分配來更改演示文稿樣式:

viewController.modalPresentationStyle = UIModalPresentationOverCurrentContext;

導致模態呈現控制器占據屏幕的一小部分,與UIPresentationController的原始呈現視圖控制器UIPresentationController

但是,使用
viewController.modalPresentationStyle = UIModalPresentationOverFullScreen
對於這種情況更好,因為他的模態控制器是全屏的。

嘗試使用:

viewController.modalPresentationStyle = UIModalPresentationOverCurrentContext;

它在iOS 8.1中幫助了我

我遇到了同樣的問題。 我已經嘗試使用符號斷點調試它,似乎在某種布局管理器上有一些內部調用來執行此操作。

雖然我無法“解決”這個問題(在我看來,這似乎是SDK中的一個錯誤),但我能夠找到解決此問題解決方法 基本上,您必須在兩個適當的時間設置所呈現視圖的正確尺寸。 像這樣:

在使用自定義UIPresentationController呈現的視圖控制器中,添加以下內容:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    dispatch_async(dispatch_get_main_queue(), ^{
        self.view.frame = [self.presentationController frameOfPresentedViewInContainerView];
    });
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    self.view.frame = [self.presentationController frameOfPresentedViewInContainerView];
}

如果你想知道:是的,你確實需要它在兩個地方做。 因為奇怪的是,當我僅在viewDidAppear異步塊中執行它時,一旦動畫結束它就會被破壞(調整為全屏)。

暫無
暫無

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

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