Iphone 使用通用应用程序自动旋转获取异常调试日志
我的通用应用程序有以下代码,但当我运行该应用程序时,我会收到一个奇怪的日志。不过,一切似乎都很顺利Iphone 使用通用应用程序自动旋转获取异常调试日志,iphone,objective-c,cocoa-touch,ipad,uiviewcontroller,Iphone,Objective C,Cocoa Touch,Ipad,Uiviewcontroller,我的通用应用程序有以下代码,但当我运行该应用程序时,我会收到一个奇怪的日志。不过,一切似乎都很顺利 - (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { if (NSClassFromString(@"UISplitViewController") != nil && UI_USER_INTERFACE_IDIOM() == UIUse
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (NSClassFromString(@"UISplitViewController") != nil && UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
return YES;
}
else
return NO;
}
在控制台中:
The view controller <UINavigationController: 0x1468d0> returned NO from -shouldAutorotateToInterfaceOrientation: for all interface orientations. It should support at least one orientation.
对于所有接口方向,视图控制器从-shouldAutorotateToInterfaceOrientation:返回NO。它应该至少支持一个方向。
我认为这意味着你的if条件总是错误的。无论是iPad还是UISplitViewController类,对于纵向还是横向都应该返回YES。例如,对于iPhone,您的始终会返回“否”。从类似的内容开始,然后可能仅在blahblah:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (NSClassFromString(@"UISplitViewController") != nil && UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
return YES;
}
else
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}
信息说明了一切: 它应该至少支持一个方向 在
else
语句中,NO
独立于方向返回。如果NO
此处表示“仅纵向”,请进行检查并返回纵向的YES
:
else
return
(interfaceOrientation == UIInterfaceOrientationPortrait) ?
YES :
NO ;
或者更简洁(但不那么华丽)的版本:
我认为您的
if
条件总是失败,因此您可能总是返回NO
,这意味着“我不支持任何方向”,这显然是不正确的。。。您希望支持的最低目标是什么
如果您的else
应该处理iPhone/iPod,您应该返回YES
至少一个方向:
return (interfaceOrientation == UIInterfaceOrientationPortrait);
或
如果您计划支持所有方向
如果您关心支持低于3.2的iOS版本,并想在模拟器上测试它,您可能需要将“iPad检查”更改为类似的内容
- (BOOL)amIAnIPad {
// This "trick" allows compiling for iOS < 3.2 and testing on pre 3.2 simulators
#if (__IPHONE_OS_VERSION_MAX_ALLOWED >= 30200)
if ([[UIDevice currentDevice] respondsToSelector: @selector(userInterfaceIdiom)])
return ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad);
#endif
return NO;
}
-(BOOL)阿米尼派{
//这种“技巧”允许编译iOS<3.2版本,并在3.2之前的模拟器上进行测试
#如果(\uuuuIphone\uOS\uVersion\uMax\uAllowed>=30200)
if([[UIDevice currentDevice]respondsToSelector:@selector(userInterfaceIdiom)])
返回([UIDevice currentDevice].userInterfaceIdiom==UIUserInterfaceIdiomPad);
#恩迪夫
返回否;
}
更多关于该技巧的信息,请访问
return inOrientation == UIDeviceOrientationLandscapeLeft
|| inOrientation == UIDeviceOrientationLandscapeRight
|| inOrientation == UIDeviceOrientationPortrait
|| inOrientation == UIDeviceOrientationPortraitUpsideDown;
- (BOOL)amIAnIPad {
// This "trick" allows compiling for iOS < 3.2 and testing on pre 3.2 simulators
#if (__IPHONE_OS_VERSION_MAX_ALLOWED >= 30200)
if ([[UIDevice currentDevice] respondsToSelector: @selector(userInterfaceIdiom)])
return ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad);
#endif
return NO;
}