1

i have a scrollview with some subviews. Inside this subviews i have other subviews.

i want to present a popover that is anchored to one of this "nested" subviews.

I correctly show the popover, and it is anchored to the corrected subview, but whenever i scroll the scrollview, the popover doesn't move with the scrollview. I would like my popover to move and to adjust its "x" origin every time i scroll the scrollview horizontally.

This is the code i use to present the popover.

func showAlarmViewController(notification: NSNotification){

    troubleViewController = TroubleshootViewController()
    troubleViewController!.modalPresentationStyle = .Popover
    troubleViewController!.preferredContentSize = CGSizeMake(300.0, 150.0)

    popoverMenuViewController = troubleViewController!.popoverPresentationController
    popoverMenuViewController!.permittedArrowDirections = .Down
    popoverMenuViewController!.delegate = self
    popoverMenuViewController!.passthroughViews = [self.detailScrollView]
    popoverMenuViewController!.sourceView = (notification.object as! UIView).superview
    popoverMenuViewController!.sourceRect = CGRect(x: -100, y: 100, width: 300, height: 150)

    presentViewController(
        troubleViewController!,
        animated: true,
        completion: nil)

}

any help please? thanks!

yax
  • 123
  • 1
  • 13

1 Answers1

0

You have to add your popoverMenuViewController in one of the nested subviews of scrollview or in scrollview by

scrollview.addsubview(popoverMenuViewController)  

If popoverMenuViewController controller is UIViewController, then add container view in scrollview and link that container view to popoverMenuViewController. later you can add container view as a subview of scrollview.

here, is the link how container view can be implemented. How to use a 'Container View' in iOS?
And
http://spin.atomicobject.com/2015/07/21/ios-container-views/

or add popoverMenuViewController in one of the nested subview of scrollview

subviewofscrollview.addsubview(popoverMenuViewController)

Set your popoverMenuViewController anchor according to the subview content size, where you added this popoverMenuViewController.

Community
  • 1
  • 1
Kiran Jasvanee
  • 6,362
  • 1
  • 36
  • 52
  • popoverMenuViewController is a UIPopoverPresentationController, i can't add it as a subview. – yax Feb 04 '16 at 10:54
  • I edited the code and given some links how you can use container view. – Kiran Jasvanee Feb 04 '16 at 11:03
  • i understand, but can't i use the native "presentViewController" function? because i remember that i did this stuff in obj-c, but i don't remember how.. probably i did something in the scrollViewDidScroll method.. i would like to use the native popover because it automatically shows the popover in the correct position – yax Feb 04 '16 at 11:09