How to add a view on top of a UIPopoverController

I have an iPad app with a drawer table displayed in a popover. The user can click and hold an item in the box to drag this item out of it and into my main view. This part works great; unfortunately, the dragged view appears under the popover and is too small to be visible until it is pulled out from under it. If I add the view as a subcontrol of the view controller in the popover, it will be cropped by the popover frame, and since I cannot access the UIPopoverController , I cannot turn off its masksToBounds layer, and that would probably not be a great idea. I suspect that I could use an extra UIWindow with a high windowLevel to make the dragged view appear on top of the popover, but that seems redundant. Is there a better solution?

+4
source share
2 answers

Got it. UIWindow working fine. The 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; 
+7
source

Adding a Swift Version:

  let windows: [UIWindow] = UIApplication.shared.windows let firstWindow: UIWindow = windows[0] firstWindow.addSubview(loadingView) firstWindow.bringSubview(toFront: loadingView) 

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

0
source

Source: https://habr.com/ru/post/1306692/


All Articles