View being blocked by UITransitionView after being presented

我的梦境 提交于 2019-12-18 12:18:45

问题


I have a side navigation controller and present it via a UIButton. When I make this NC the root view controller directly by [self presentviewcontroller: NC animated: YES completion: nil], some reason the menu side of the NC is blocked by a UITransitionView that I cannot get to disappear.

I've attached an image of the . is another.

I have tried the following:

UIWindow *window = [(AppDelegate *)[[UIApplication sharedApplication] delegate] window];
    window.backgroundColor = kmain;


    CATransition* transition = [CATransition animation];
    transition.duration = .5;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type = kCATransitionPush;
    transition.subtype = kCATransitionFromTop;

    [nc.view.layer addAnimation:transition forKey:kCATransition];

    [UIView transitionWithView:window
                      duration:0.5
                       options:UIViewAnimationOptionTransitionNone
                    animations:^{ window.rootViewController = nc; }
                    completion:^(BOOL finished) {
                        for (UIView *subview in window.subviews) {
                            if ([subview isKindOfClass:NSClassFromString(@"UITransitionView")]) {
                                [subview removeFromSuperview];
                            }
                        }
                    }];

But it is very hacky, and as the rootviewcontroller of the window changes during the transition, it's a little choppy and part of the navigationcontroller and the top right corner turn black. It looks very bad.


回答1:


To get tap events through the UITransitionView, set the containerView's userInteractionEnabled to false. This is if you're doing a custom transition animation by using UIViewControllerAnimatedTransitioning.

Example, in your animateTransition(_:):

func animateTransition(transitionContext: UIViewControllerContextTransitioning) {

    let containerView = transitionContext.containerView()        
    containerView.userInteractionEnabled = false

    ...
}



回答2:


I had the same issue but in a little different scenario, I ended up doing something very similar to find the view but instead of removing the view which can be more problematic I disabled the user interaction so any touch events just go throw it and any other objects can handle to user's interaction. In my case this was only present after updating the app to iOS 10, the same code running in iOS 9 didn't fall into this.




回答3:


I was facing the same issue, and this solved issue for me,

navigationController.setNavigationBarHidden(true, animated: false)

This worked for me as I am having custom view as navigation bar in view controllers.




回答4:


Ive had this issue when I was setting accessibilityElements on a popover view controller. I fix it by removing assigning an array of elements.




回答5:


I had a similar issue where a UITransitionView kept blocking my views, preventing any user interaction.

In my case this was due to an uncompleted custom animated UIViewController transition.

I forgot to properly complete my transition with:

TransitionContext.completeTransition(transitionContext.transitionWasCancelled)

or

TransitionContext.completeTransition(!transitionContext.transitionWasCancelled)

In the

func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {}

from the UIViewControllerAnimatedTransitioning protocol



来源:https://stackoverflow.com/questions/36142576/view-being-blocked-by-uitransitionview-after-being-presented

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!