【问题标题】:Popover image gallery not working in iPad iOS Swift弹出框图片库在 iPad iOS Swift 中不起作用
【发布时间】:2015-11-08 06:25:14
【问题描述】:

最近我的应用被 App Review 拒绝了,因为我没有使用 Popover。 然后我将我的编码更改为以下。但我仍然没有在模拟器中弹出窗口。

总是得到正常的iPhone照片选择方法,它使应用程序崩溃。

而且它甚至没有打印“工作”。

 @IBAction func chooseGallery(sender: UIBarButtonItem) {

    imagePicker.sourceType = .PhotoLibrary

  //imagePicker.modalPresentationStyle = .Popover
  //presentViewController(imagePicker, animated: true, completion: nil)//4
  //imagePicker.popoverPresentationController?.barButtonItem = sender

    if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
        self.presentViewController(imagePicker, animated: true, completion: nil)
    }
    else {
        println("Working")// to test this part

        imagePicker.modalPresentationStyle = .Popover
        presentViewController(imagePicker, animated: true, completion: nil)//4
        imagePicker.popoverPresentationController?.barButtonItem = (sender)

        imagePicker.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.Up
        imagePicker.popoverPresentationController?.sourceRect = CGRect(x: 150, y: 150, width: 0, height: 0)
     }     
}

【问题讨论】:

  • 我找到了答案。我没有在目标设备中使用universal

标签: ios iphone swift ipad popover


【解决方案1】:

你的代码经过一些修改对我来说很好,在下面的例子中,我将像你一样只为 iPad 展示一个 Popover。

@IBAction func showNextViewController(sender: UIBarButtonItem) {

    let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
    let nextViewController = storyBoard.instantiateViewControllerWithIdentifier("NextViewController") as! NexViewController

    if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
        self.presentViewController(nextViewController, animated: true, completion: nil)
    }
    else {            
        nextViewController.modalPresentationStyle = .Popover
        presentViewController(nextViewController, animated: true, completion: nil)

        if let popover = nextViewController.popoverPresentationController {             
            popover.barButtonItem = sender
            popover.permittedArrowDirections = UIPopoverArrowDirection.Up

            // to set it size
            nextViewController.preferredContentSize = CGSizeMake(200,500)
        }
    }    
}

因为我不知道你想要展示的 UIViewController 的类,所以我自己做了一个,里面什么都没有,我在 @IBAction 中实例化它以避免保留对它的引用(仅用于测试目的)。

只是一些观察:

  • 当您要呈现弹出框时,您只需设置以下两个之一:

    • barButtonItem
    • sourceView, sourceRect

在上面的例子中,就像你设置barButtonItem你不需要更多的东西。

希望对你有所帮助。

【讨论】:

    【解决方案2】:

    试试这个,

    picker.modalPresentationStyle = .CurrentContext

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-25
      • 1970-01-01
      相关资源
      最近更新 更多