我在Xcode中遇到iPhone X模拟器的问题与其他模拟器的行为不同。
我尝试做的只需点击一个显示UIPicker的视图。选择日期并且用户单击“确定”后,弹出窗口将消失,并且视图中的标签将使用所选内容的字符串进行更新。这适用于我使用的2个物理设备(iPhone6 plus和iPad)。它也在iPhone 5和8的模拟器中工作。但是,当我尝试使用iPhoneX时,它无法正常工作。
一旦用户点击选择器或移动它,它就会淡出屏幕并且不会更新任何内容。因为我没有物理iPhoneX进行测试,所以我不知道这只是一个模拟器问题,还是在实际设备上也会发生。这只是一个模拟器问题吗?我怎样才能解决这个问题?这也会发生在实际的设备上吗?
以下是我用来显示包含选择器视图的自定义弹出框的功能。
/// When the view is tapped it will display user options and then update the label in the view.
///
/// - Parameters:
/// - box: LabelAndWhiteBarView is my own custom UIView for this project.
/// - strings: array of strings to be displayed by the picker
func displayStringPicker(box: LabelAndWhiteBarView, strings: [String]){
// Custom viewcontroller containing a UIPickerView, title UILabel and a cancel and OK UIButton.
let floatingPickerViewController:FloatingPickerViewController = UIStoryboard(name: "FloatingPickerStoryboard", bundle: nil).instantiateInitialViewController()! as! FloatingPickerViewController
floatingPickerViewController.modalPresentationStyle = .popover
floatingPickerViewController.preferredContentSize = defaultPickerSize // set elsewhere so it doesnt cover the whole screen
//Adds a blank string in front of each array so the user can always pick and empty option
var stringsWithBlankFirstOption = strings
stringsWithBlankFirstOption.insert("", at: 0)
floatingPickerViewController.stringArray = stringsWithBlankFirstOption
//tells the picker view which view to update
floatingPickerViewController.senderBox = box
floatingPickerViewController.delegate = self
floatingPickerViewController.view.layer.borderWidth = 1
floatingPickerViewController.view.layer.borderColor = UIColor.clear.cgColor
let popoverMenuViewController = floatingPickerViewController.popoverPresentationController
popoverMenuViewController?.permittedArrowDirections = UIPopoverArrowDirection(rawValue:0) // removed the arrow thats defauls on a popover
popoverMenuViewController?.delegate = self
popoverMenuViewController?.sourceView = self.view
popoverMenuViewController?.sourceRect = CGRect(
x: 0,
y: 0,
width: self.view.frame.width,
height: self.view.frame.height)
floatingPickerViewController.dismissBlock = {
self.dismiss(animated: false, completion: nil)
}
present(
floatingPickerViewController,
animated: false,
completion: nil)
/// set the picker to preselect what was already selected
let indexOfSelectedItem = floatingPickerViewController.stringArray.index(of: box.displayLabel.text ?? "") ?? 0
//pre selects the last selected string
floatingPickerViewController.numberPicker.selectRow(indexOfSelectedItem, inComponent: 0, animated: false)
}