UIPopoverController, Xcode 6, IOS 8 using Swift

前端 未结 3 1642
粉色の甜心
粉色の甜心 2021-02-04 22:13

I\'m having some trouble getting a UIPopover to appear using swift. The code that is commented out works fine in Objective-C, but doesn\'t work using Swift. When I tap the + in

3条回答
  •  一向
    一向 (楼主)
    2021-02-04 22:43

    Display Popover with contentView from xib

    func showPopover(sender: AnyObject) {
    
        let contentViewController = UINib(nibName: "ContentVC", bundle: nil).instantiateWithOwner(nil, options: nil)[0] as ContentVC
        contentViewController.modalPresentationStyle = UIModalPresentationStyle.Popover
    
        var detailPopover: UIPopoverPresentationController = contentViewController.popoverPresentationController!
        detailPopover.delegate = self
        detailPopover.barButtonItem = sender as UIBarButtonItem
        detailPopover.permittedArrowDirections = UIPopoverArrowDirection.Any
        presentViewController(contentViewController,
            animated: true, completion:nil)
    }
    

    Next allows to make not full screen PopoverView on iPhone for this do not forget to inherit MainViewController: UIPopoverPresentationControllerDelegate and set delegate to PopoverView

    func adaptivePresentationStyleForPresentationController(controller: UIPresentationController!) -> UIModalPresentationStyle 
    {
        return .None
    }
    

提交回复
热议问题