在iPhone上的UITableView中将UIDatePicker显示为Popover

时间:2015-06-22 17:07:34

标签: iphone uitableview uipopovercontroller

我希望显示具有UIModalPresentationPopover演示风格的日期选择器,虽然它在iPad上运行良好,但在iPhone上显示时会出现黑屏。 编辑:具体来说,它只是全屏显示,所以效果是黑屏,除非我手动为元素添加颜色。默认颜色适用于Popover演示文稿。

生成选择器和弹出窗口的代码是:

let datePicker = UIDatePicker()
datePicker.datePickerMode = .DateAndTime
datePicker.minuteInterval = 5

let vc = UIViewController()
vc.view.addSubview(datePicker!)
vc.preferredContentSize = datePicker.frame.size
vc.modalPresentationStyle = .Popover

let cell = self.tableView.cellForRowAtIndexPath(NSIndexPath(forRow: 0, inSection: 1))
let ppc = vc.popoverPresentationController
ppc?.delegate = self
ppc?.sourceRect = cell.accessoryView!.frame
ppc?.sourceView = cell

self.presentViewController(vc, animated: true, completion: nil)

cell的值在两种类型的设备上都显示正确,但我注意到所呈现的viewController的视图大小在iPhone上搞砸了。演示文稿完成后,两个设备上preferredContentSize属性的值为(320.0, 216.0),但view.frame.size在iPhone上变为(320.0, 568.0)(在iPhone 5上为全屏,它在iPhone上的行为也类似),而在iPad上它仍然符合首选尺寸。

在iPad上看起来很棒:

Looks great on iPad

我从UIViewController UITableViewController呈现相同类型的用户界面时遇到了问题。func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle { return .None } 还有什么需要做的才能在iPhone上使用tableView进行这种演示风格吗?

修改 固定。为此,需要向呈现控制器添加一个方法:

# gem install puppet --version 2.7.11
Successfully installed puppet-2.7.11

RDoc::Parser::Ruby failure around line 224 of
lib/puppet/parser/scope.rb

Before reporting this, could you check that the file you're documenting
has proper syntax:

  /usr/bin/ruby -c lib/puppet/parser/scope.rb

RDoc is not a full Ruby parser and will fail when fed invalid ruby programs.

The internal error was:

    (SystemStackError) stack level too deep

ERROR:  While executing gem ... (SystemStackError)
    stack level too deep

1 个答案:

答案 0 :(得分:0)

这是我在UIViewController

的文档中找到的内容
  

modalPresentationStyle

     

演示文稿样式决定了模态   显示的视图控制器显示在屏幕上。在水平方向   紧凑的环境,总是呈现模态视图控制器   全屏

你可以做的是,在iPhone上,将视图的backgroundColor设置为黑色,使用.15 alpha,并将选择器放在底部。

您可能需要将modalPresentationStyle设置为UIModalPresentationOverFullScreen,否则会删除下方的视图。

相关问题