JLo*_*ewy 6 objective-c uikit ios swift iphone-6-plus
在我的iPhone应用程序上,我只限于项目目标部署信息下的肖像
我只想在横向上有一个页面,我使用supportedInterfaceOrientations方法来获取它.
标准实施:
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.Landscape
}
Run Code Online (Sandbox Code Playgroud)
它适用于除iPhone 6+以外的所有iPhone设备和iOS版本.从不调用supportedInterfaceOrientations方法.
我无法找到任何可能影响iPhone 6+的原因,任何提示都会受到极大的影响.
Cal*_*ter -1
看看这个问题,试试这个代码片段:
- (NSUInteger) supportedInterfaceOrientations
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
// iPhone 5S and below: 320x480
// iPhone 6: 375x667
// iPhone 6 Plus: 414x736
CGSize screenSize = [UIScreen mainScreen].bounds.size;
// The way how UIScreen reports its bounds has changed in iOS 8.
// Using MIN() and MAX() makes this code work for all iOS versions.
CGFloat smallerDimension = MIN(screenSize.width, screenSize.height);
CGFloat largerDimension = MAX(screenSize.width, screenSize.height);
if (smallerDimension >= 400 && largerDimension >= 700)
return UIInterfaceOrientationMask.Landscape;
else
return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
}
else
{
// Don't need to examine screen dimensions on iPad
return UIInterfaceOrientationMask.Landscape;
}
}
Run Code Online (Sandbox Code Playgroud)
由于缺乏官方的 Apple API,这是我想出的解决方法:
[代码]
该代码片段只是假设尺寸高于半任意选择的尺寸的屏幕适合旋转。半任意,因为 400x700 的阈值包括 iPhone 6 Plus,但不包括 iPhone 6。
虽然这个解决方案相当简单,但我喜欢它正是因为它不复杂。我真的不需要准确区分设备,因此任何聪明的解决方案(例如Jef 的答案中的解决方案)对于我的目的来说都是矫枉过正的。
我所做的只是将第一个和第三个返回值从 更改UIInterfaceOrientationMaskAll为UIInterfaceOrientationMask.Landscape。