为什么在iOS 8中,我的应用程序在发布时方向错误?
我的iOS 7应用程序运行正常。今天我用Xcode 6尝试了它,当我运行它时,我有一个令人讨厌的惊喜:(: 您可以看到Xcode现在绘制我的viewController,就像它处于纵向模式一样,但您可以看到它处于横向模式 你知道iOS 8中发生了什么变化吗?:/ 我使用了以下定向方法:为什么在iOS 8中,我的应用程序在发布时方向错误?,ios,ipad,cocoa-touch,uiinterfaceorientation,Ios,Ipad,Cocoa Touch,Uiinterfaceorientation,我的iOS 7应用程序运行正常。今天我用Xcode 6尝试了它,当我运行它时,我有一个令人讨厌的惊喜:(: 您可以看到Xcode现在绘制我的viewController,就像它处于纵向模式一样,但您可以看到它处于横向模式 你知道iOS 8中发生了什么变化吗?:/ 我使用了以下定向方法: (整数)支持的接口方向 (BOOL)应该自动旋转 (布尔)应自动旋转指针面定向:(UIInterfaceOrientation)interfaceOrientation 编辑: 我刚刚发现这个方法: - (
- (整数)支持的接口方向
- (BOOL)应该自动旋转
- (布尔)应自动旋转指针面定向:(UIInterfaceOrientation)interfaceOrientation
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskLandscape;
}
现在我的第一个ViewController工作正常:)。问题是,当我展示一个模式(改变UIInterfaceOrientationMaskAll中的方法集)时,我重新制作了屏幕截图的丑陋效果。
正是在这种模式下,我更改了我的方法:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if(self.restrictRotation)
{
return UIInterfaceOrientationMaskLandscape;
}
else
{
return UIInterfaceOrientationMaskAll;
}
}
// THIS IS A DELEGATE OF MODAL VIEW CONTROLLER
- (void)updateInterfaceAfterDocumentPreviewViewController
{
NSLog(@"updateInterfaceAfterDocumentPreviewViewController");
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft];
AppDelegate* appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
appDelegate.restrictRotation = YES;
}
这种检测方向的方法是可行的(但现在仍然允许)。 它被尺寸和等级的概念所取代 (奇怪的是,我现在似乎在苹果的在线文档中找不到尺寸等级参考——我发誓它以前就在那里——也许在XCode中)。看 无论如何,界面生成器中有一个复选框,上面写着“.”
你能检查一下吗。将其关闭并查看是否有帮助?请尝试以下代码 在
AppDelegate
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
[self.window setFrame:[[UIScreen mainScreen] bounds]]; //Add
问题似乎在于设置窗口时的呼叫顺序。在应用程序委托的
didfishlaunchingwithoptions
方法中指定rootViewController
之前,需要调用makeKeyAndVisible。以下工作:
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
[self.window makeKeyAndVisible];
self.window.rootViewController = self.myMainViewController;
但如果您将订单更改为:
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.rootViewController = self.myMainViewController;
[self.window makeKeyAndVisible];
你会得到你正在经历的行为。我在“加载屏幕”上也遇到了同样的问题。这就是我的工作。(请注意:我的应用程序仅支持iOS 7或更高版本的横向模式。):
CGRect theFrame=self.view.frame;
如果([[UIDevice currentDevice]systemVersion]floatValue]<8.0){
CGRect屏幕边界=[[UIScreen mainScreen]边界];
theFrame.origin=CGPointZero;
theFrame.size.width=screenBounds.size.height;
frame.size.height=screenBounds.size.width;
}
NSLog(@“%@,[NSNumber-valueWithCGRect:theFrame]);
self.loadingScreen=[[UIView alloc]initWithFrame:theFrame];
如果您的应用程序支持纵向定位,请参考Mike Hay的答案,并了解“计算正确应用程序框架的漫长道路”:
希望这能有所帮助。旧学校解决方案:
BOOL portrait;
BOOL iOS8OrLater = ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0);
if (iOS8OrLater) {
CGFloat height = CGRectGetHeight(self.view.frame);
CGFloat width = CGRectGetWidth(self.view.frame);
if (width / height > 1.0) {
portrait = NO;
} else {
portrait = YES;
}
} else {
portrait = UIInterfaceOrientationIsPortrait(self.interfaceOrientation);
}
if(portrait) {
[self layoutPortrait];
} else {
[self layoutLandscape];
}
您可以在viewWillLayoutSubviews中调用它。请查看.plist文件
UIInterfaceOrientation currentOrientation = [UIApplication sharedApplication].statusBarOrientation;
if( UIDeviceOrientationIsLandscape( currentOrientation ) )
{
if( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad )
{
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];
// -- Fix for rotation issue for ios 8
if( IS_IOS_8_OR_LATER )
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPad"
bundle: nil];
// -- Set frame of nav controller
UINavigationController *nc = [storyboard instantiateViewControllerWithIdentifier:@"NavController"];
self.window.rootViewController = nc;
[self.window setFrame:[[UIScreen mainScreen] bounds]];
// -- Set fame of home view controller
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"Home"];
self.window.rootViewController = vc;
[self.window makeKeyAndVisible];
[self.window setFrame:[[UIScreen mainScreen] bounds]];
}
}
}
确保已将“初始界面方向”设置为所需的方向
在“支持的界面方向”中,将首选方向作为列表中的第一个条目(看起来苹果改变了这个顺序)李>
我遇到了一个类似的问题,我无法获得正确的发布图片(我有两张iPad的图片,Default-grait.png和Default-Landscape.png),而且在发布图片消失后,我也无法让应用程序本身自动定向
要解决发布映像的问题:
- 转到项目的自定义iOS目标属性部分(单击项目文件列表顶部的项目图标,它应该是您看到的第一个部分)
- 在该表中添加一行名为“Launch image”(应自动填充),并在右列中输入“Default”作为字符串。
- 确保您的发布图像符合苹果的文件名准则(即:默认)-568@2x, Default@2x等)
在第一次查看控制器时解决应用程序定位问题:
- 转到项目列表文件(应为“YourApp Info.plist”)
- 添加一行并输入“支持的界面方向”
- 添加应用程序支持的方向
在真正的设备上试一试。同样的问题?很遗憾,是的:(据我所知,iOS 8不再使用自动旋转和方向API。每个方向更改都只是一个动画边界更改。感谢您的评论Legoless,请查看我对mc01的回答。我在许多第三方应用程序(例如Reeder)中看到了同样的情况。没有任何更改:(.在我看来,这是UIWindow的问题,因为如果我设置视图的背景色,我总是看到UIWindow的黑色。另外,如果我打印窗口的框架…这是正确的。当你在横向和纵向之间更改模拟器方向时,它会保持这种状态吗?还是只有当它开始运行时才保持这种状态?你使用自动布局吗?也许是这样我的限制是罪魁祸首?我在这个项目中没有使用自动布局,如果我在横向模式下运行应用程序,应用程序就会正常工作,相反,如果我在纵向模式下运行应用程序,应用程序就会像附加的屏幕截图一样显示(必须在横向模式下显示)。如果我在info.plist中更改设备方向并仅放置横向视图,则它可以工作,但我还需要纵向视图以在两个方向上显示qlpreviewcontroller。我遇到了完全相同的问题。此解决方案对我有效。谢谢!是否在某个地方记录了此问题?对我来说这似乎是一个错误,但它仍然可以工作。
UIInterfaceOrientation currentOrientation = [UIApplication sharedApplication].statusBarOrientation;
if( UIDeviceOrientationIsLandscape( currentOrientation ) )
{
if( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad )
{
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];
// -- Fix for rotation issue for ios 8
if( IS_IOS_8_OR_LATER )
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPad"
bundle: nil];
// -- Set frame of nav controller
UINavigationController *nc = [storyboard instantiateViewControllerWithIdentifier:@"NavController"];
self.window.rootViewController = nc;
[self.window setFrame:[[UIScreen mainScreen] bounds]];
// -- Set fame of home view controller
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"Home"];
self.window.rootViewController = vc;
[self.window makeKeyAndVisible];
[self.window setFrame:[[UIScreen mainScreen] bounds]];
}
}
}