gpt4 book ai didi

Swift UIUserInterfaceIdiom 错误

转载 作者:可可西里 更新时间:2023-11-01 01:06:30 30 4
gpt4 key购买 nike

我只在 iphone 5/6/6 Plus/iPad Mini/iPad 的横屏模式下使用 View ,现在我想在我的应用程序中集成 UIUserInterfaceIdiom 以在横屏模式下使用这些设备。

func openGallary()
{
picker!.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
if UIDevice.currentDevice().userInterfaceIdiom == .Phone
{
self.presentViewController(picker!, animated: true, completion: nil)
}
else
{
popover=UIPopoverController(contentViewController: picker!)
popover!.presentPopoverFromRect(btnClickMe.frame, inView: self.view, permittedArrowDirections: UIPopoverArrowDirection.Any, animated: true)
}
}

我正在尝试使用这段代码,但出现错误 UIUserInterfaceIdiomPad

最佳答案

你必须这样做:

if UIDevice.currentDevice().userInterfaceIdiom == UIUserInterfaceIdiom.Phone {
// .....
}

您还可以创建一个只读的计算属性来返回检查它,如下所示:

var iPhone: Bool {
return UIDevice.currentDevice().userInterfaceIdiom == UIUserInterfaceIdiom.Phone
}

//

var iPad: Bool {
return UIDevice.currentDevice().userInterfaceIdiom == UIUserInterfaceIdiom.Pad
}

//

if iPhone {
presentViewController(picker!, animated: true, completion: nil)
} else if iPad {
popover=UIPopoverController(contentViewController: picker!)
popover!.presentPopoverFromRect(btnClickMe.frame, inView: self.view, permittedArrowDirections: UIPopoverArrowDirection.Any, animated: true)
} else {
println("Unspecified")
}

关于Swift UIUserInterfaceIdiom 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27474434/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com