2017-03-02 75 views
0

我想从这样的PIC按钮进行酥料饼:酥料饼 - 斯威夫特

enter image description here

要做到这一点,我按照以下步骤进行:

1。我创建的视图控制器(加上一个控制器)与我改变大小它为100 * 200

2.I做出赛格瑞从第一控制器(JobsViewController)上述控制器作为present as popover和予设定的标识符:

enter image description here

3.in JobsViewController

func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 
    if segue.identifier == "showFeatureJobs" { 

     //let popoverViewController = segue.destination 
     // popoverViewController.modalPresentationStyle = UIModalPresentationStyle.popover 
     // popoverViewController.popoverPresentationController!.delegate = self 

     // get a reference to the view controller for the popover 
     let popController = UIStoryboard(name: "JobsViewController", bundle: nil).instantiateViewController(withIdentifier: "showFeatureJobs") 

     // set the presentation style 
     popController.modalPresentationStyle = UIModalPresentationStyle.popover 

     // set up the popover presentation controller 
     popController.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.up 
     popController.popoverPresentationController?.delegate = self 
     popController.popoverPresentationController?.sourceView = sender as! UIView? // button 
     popController.popoverPresentationController?.sourceRect = (sender?.bounds)! 

     // present the popover 
     self.present(popController, animated: true, completion: nil) 

    } 
} 

// MARK: - UIPopoverPresentationControllerDelegate method 

func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle { 

    // Force popover style 
    return UIModalPresentationStyle.none 
} 

4.but当我在我的按钮,我酥料饼盖点击我所有的网页:

enter image description here

哪里是我的问题?

回答

0

弹出窗口控制器应该已经由storyboard seque实例化了。您需要使用已经存在(并且尺寸适当)的那个,而不是创建一个新的。

喜欢的东西:

if let popOver = segue?.destination.popoverPresentationController, 
    { popOver.sourceRect = yourAnchor.bounds } 

我不能确定你是怎么式AnyObject的sender参数?要将.bounds属性用作sourceRect,所以我必须假设您在实际运行代码中的其他位置获得了适当的动态锚点位置坐标。

0

和我一样的情况发生。它不是被称为适当的代表。你应该用swift(3.0,4.0)等适当的语言调用委托函数。希望这将有助于你

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

Image