How to add a view on top of a UIPopoverController

好久不见. 提交于 2019-11-29 22:27:04

问题


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?


回答1:


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;



回答2:


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



来源:https://stackoverflow.com/questions/2622063/how-to-add-a-view-on-top-of-a-uipopovercontroller

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