sammcewan / WYPopoverController

WYPopoverController is for the presentation of content in popover on iPhone / iPad devices. Very customizable.
Other
252 stars 74 forks source link

popover in a modally presented viewcontroller #85

Open kampfgnu opened 7 years ago

kampfgnu commented 7 years ago

presenting a popover in a modal viewcontroller (presentPopoverAsDialogAnimated) does not work. any solutions/hints how to fix this?

vitalys commented 7 years ago

Is your problem the same as #22? If yes, I'll try to address it tomorrow. If no, could you provide more detailed steps/some code to reproduce it? Thanks!

pagrit commented 7 years ago

There is no error, the popover just not displayed.

I want to show the popover after tapping a button therefore i use following code:

`
func buttonTapped(sender: AnyObject){ self.setupBlurAndVibrancy() //other stuff }

func setupPopover() { let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.Dark) blurEffectView = UIVisualEffectView(effect: blurEffect) blurEffectView!.alpha = 0.7 blurEffectView!.frame = view.bounds self.view.addSubview(blurEffectView!)

    let contentViewController = PopoverContentViewController(nibName: "PopoverContentViewController", bundle: nil)
    self.popover = WYPopoverController(contentViewController: contentViewController)
    self.popover!.setPopoverContentSize( CGSizeMake(200.0, 300.0), animated: true)
    self.popover!.presentPopoverAsDialogAnimated(true)

    contentViewController.popoverButton.setTitle("user.popover.login-now".localized, forState: .Normal)
    contentViewController.popoverDismissButton.setTitle("user.popover.dont-login".localized, forState: .Normal)
    contentViewController.popoverIcon.image = UIImage(named: "SuccessIcon")
    contentViewController.popoverLabel.text = "user.popover.need-login".localized

    contentViewController.popoverDismissButton.addTarget(self, action: "dismissPopover:", forControlEvents: UIControlEvents.TouchUpInside)

    contentViewController.popoverButton.addTarget(self, action: "loginTapped:", forControlEvents: UIControlEvents.TouchUpInside)

    self.popover?.delegate = self
}

`

i use this code in several parts in the project, sometimes it works and the popover will displayed. sometime only the blureffect appears.

kampfgnu commented 7 years ago

as pagrit says, there are no errors. the popover just doesn't display. even the method "popoverControllerDidPresentPopover(popoverController: WYPopoverController!)" is called, but nothing is presented. i guess the view where the popover is attached to is not visible, or somewhere behind the modally presented viewController...

vitalys commented 7 years ago

Thank you, I'll take a look. BTW, it will be really helpful if you share test project that reproduces this problem.

kampfgnu commented 7 years ago

i made a little test project: https://nousguide.box.com/s/ydpgxw66tb703hd0dkjoxwyneayn23dk just download and unzip the file. open "PopoverTest.xcworkspace" and run the app. on the first screen/viewController, there is a working popover. when you hit the button (after dismissing the popover), another viewController is presented modally, (not) showing a popover in the viewDidAppear. the _inView.window property is nil in the case of modally presented viewController, but i don't know how to workaround... cheers!

vitalys commented 7 years ago

@kampfgnu You have to set preferred content size for the content view controller before displaying it as modal popover. Add contentViewController.preferredContentSize = CGSizeMake(200, 200) after contentViewController creation and your issue will be solved.

@pagrit ^

kampfgnu commented 7 years ago

hmmm, did it work for you in the modal (magenta colored) viewController? i tried, but still no success...

vitalys commented 7 years ago

I haven't checked it in the magenta colored view controller. Let me check

vitalys commented 7 years ago

Ok, I can reproduce it.

pagrit commented 7 years ago

are there any news? or hot fixed? or ideas why it doesn't work?

algrid commented 7 years ago

Added a fix for this - https://github.com/sammcewan/WYPopoverController/pull/87 Could anyone try it?