PopOver视图控制器覆盖全屏

时间:2016-11-25 07:45:15

标签: ios swift

这是我的PopOver代码。我有两个View控制器。我在Messaging View控制器中展示PopOver,需要管道的视图控制器是PreferencesView控制器。 Storyboard Id也是相同的Preferences View控制器。 popOver成功但始终覆盖全屏。即使 UIModalPresentationStyle.None 。我在这里做错了什么?

 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)
    }

3 个答案:

答案 0 :(得分:3)

我猜你是从故事板上表演的。如果您这样做,请从故事板中删除segue并为条形按钮项创建操作并将此代码放在那里。

this->get_allocator() == other.get_allocator()

答案 1 :(得分:2)

在您调用popover

的位置实现此功能
func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
    return .none
}

答案 2 :(得分:0)

尝试添加

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

我希望它会有所帮助