Search code examples
autolayoutuipopovercontroller

UIPopoverController displays at wrong position


I want to show a UIPopoverController when clicking on a label. All elements are laid out with AutoLayout.

// In TorHeimPopoverViewController.swift
// self.view is TorHeimPopoverViewController's view

popover.presentPopoverFromRect(label.frame, inView: self.view, permittedArrowDirections: UIPopoverArrowDirection.Left, animated: true)

It's displayed in another UIPopoverController (TorHeimPopoverViewController) and there in a Container

MainAppView -> TorHeimPopoverViewController -> ContainerView

enter image description here

How can I fix this?


Solution

  • The problem is, the inView parameter is wrong for this purpose. The rect of label.frame is in relation to the ContainerView, in which it is.

    For example, when label.frame is x = 300, y = 100, it will take these coordinates, but use self.view as origin and not the container.

    enter image description here