How to add a view on top of a UIPopoverController

2019-02-10 17:53发布

I've got an iPad app with a “drawer” table displayed in a popover. The user can tap-and-hold on an item in the drawer to drag that item out of it and into my main view. That part works fine; unfortunately, the view being dragged appears under the popover, and is too small to be visible until it's dragged out from underneath it. If I add the view as a subview of the view controller in the popover, it gets clipped by the popover's frame, and as I can't access the UIPopoverController's view, I can't disable its layer's masksToBounds—and that probably wouldn't be a great idea anyway. I suspect that I could use an additional UIWindow with a high windowLevel value to force the dragged view to appear on top of the popover, but this seems like overkill. Is there a better solution?

2条回答
相关推荐>>
2楼-- · 2019-02-10 18:18

Adding the Swift Version:

    let windows: [UIWindow] = UIApplication.shared.windows
    let firstWindow: UIWindow = windows[0]

    firstWindow.addSubview(loadingView)
    firstWindow.bringSubview(toFront: loadingView)

EDIT to admin: thanks for the review – deleted my other answer in duplicate How to show a UIView OVER a UIPopoverController

查看更多
Anthone
3楼-- · 2019-02-10 18:22

Got it. UIWindow works fine. Code:

// when drag starts
draggingView = [[UIWindow alloc] initWithFrame:CGRectMake(0,0,100,100)];
draggingView.windowLevel = UIWindowLevelAlert;
draggingView.center = [gestureRecognizer locationInView:self.view.window];
[draggingView makeKeyAndVisible];

// when drag ends
[draggingView release];
draggingView = nil;
查看更多
登录 后发表回答