简体   繁体   English

PopOver视图控制器覆盖全屏

[英]PopOver view controller covers full screen

This is my code for PopOver. 这是我的PopOver代码。 I have two View controllers. 我有两个View控制器。 I am presenting the PopOver in Messaging View controller and the view controller that need to be piped is PreferencesView controller. 我正在Messaging View控制器中显示PopOver,需要通过管道传递的视图控制器是PreferencesView控制器。 Storyboard Id is also same Preferences View controller. 情节提要ID也与“偏好设置视图”控制器相同。 The popOver is success but always covers the full screen. popOver是成功的,但始终覆盖全屏。 Even though UIModalPresentationStyle.None . 即使UIModalPresentationStyle.None What am I doing wrong here? 我在这里做错了什么?

 func optionClicked(sender:UIBarButtonItem)
{
    print(")show set preference and set reminder option")


    let preferenceAction: UIAlertAction = UIAlertAction(title: "Set preferences", style: .Default) { action -> Void in
        self.optionChoosed(true)
        }
    let reminderAction: UIAlertAction = UIAlertAction(title: "Set reminder", style: .Default) { action -> Void in
        self.optionChoosed(false)
    }
    let actionSheetController: UIAlertController = UIAlertController(title: kAlertTitle, message: "What you want to do?", preferredStyle: .ActionSheet)

    let cancelAction: UIAlertAction = UIAlertAction(title: "Cancel", style: .Cancel) { action -> Void in
    }
    actionSheetController.addAction(preferenceAction)
    actionSheetController.addAction(reminderAction)
    actionSheetController.addAction(cancelAction)
    self.presentViewController(actionSheetController, animated: true, completion: nil)
}

func optionChoosed(isSetPreference:Bool)
{


    if(isSetPreference)
    {
    print("Set preference")

        let storyboard : UIStoryboard = UIStoryboard(name: "Messaging", bundle: nil)
        let vc = storyboard.instantiateViewControllerWithIdentifier("PreferencesViewController") as! PreferencesViewController
        vc.modalPresentationStyle = UIModalPresentationStyle.Popover
        let popover: UIPopoverPresentationController = vc.popoverPresentationController!
        popover.barButtonItem?.action = "isSetPreference"
        popover.delegate = self
        presentViewController(vc, animated: true, completion:nil)


    }

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

    }
    func dismiss() {
        self.dismissViewControllerAnimated(true, completion: nil)
    }

I guess you are performing segue from storyboard. 我猜您正在从情节提要中执行segue。 if you are doing so remove segue from storyboard and create an action for bar button item and put this code there. 如果这样做,则从情节提要中删除segue并为条形按钮项创建一个动作,然后将此代码放在此处。

    let storyboard : UIStoryboard = UIStoryboard(name: "Messaging", bundle: nil)
    let vc = storyboard.instantiateViewControllerWithIdentifier("PreferencesViewController") as! PreferencesViewController
    vc.modalPresentationStyle = UIModalPresentationStyle.Popover
    let popover: UIPopoverPresentationController = vc.popoverPresentationController!
    vc.preferredContentSize = CGSize(width: 200, height: 200)
    popover.barButtonItem = sender as? UIBarButtonItem
    popover.delegate = self
    presentViewController(vc, animated: true, completion:nil)

Implement this function where you call the popover 在调用弹出窗口的地方实现此功能

func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
    return .none
}

Try to add 尝试添加

vc.preferredContentSize = CGSize(width: 200, height: 200)

I hope it will help 希望对您有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM