我遇到了有关iphone屏幕方向的问题。我的应用程序的基础sdk是ios 6.0,部署目标是4.3并在ios 5.0和5.1上运行
在应用程序的plist文件中,我设置了Portrait (bottom home button)
,Landscape (left home button)
和Landscape (right home button)
。我正在开发一款通用应用。因此,在每个视图的- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
方法中,我有条件地为iphone返回portrait
,为ipad返回landscape
。
我的导航流程是:
UINavigatinController
推UITableViewControler
第一个标签UINavigationController
rootViewController
逐个推送2个观看次数。
在我上一次viewController的- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
方法中,我返回了YES
。但应用程序此视图根本不是旋转。甚至没有调用- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
方法。 :(
我的要求是只支持横向和纵向方向,只支持一个viewController而不支持整个应用程序。
请帮帮我。
答案 0 :(得分:1)
您可以通过View Controller Class中的此代码解决此Orientation问题。
#ifdef IOS_OLDER_THAN_6
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) ||
(toInterfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
#endif
#ifdef IOS_NEWER_OR_EQUAL_TO_6
-(BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return (UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight); //IOS_5
}
#endif
您必须在.pch文件中定义此代码。
代码:
#define IOS_OLDER_THAN_6 ([[[UIDevice currentDevice] systemVersion] floatValue] < 6.0)
#define IOS_NEWER_OR_EQUAL_TO_6 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 6.0)
希望它有效。
感谢。
答案 1 :(得分:0)
对于iOS 6,请使用supportedInterfaceOrientations
&amp; shouldAutorotate
代替shouldAutorotateToInterfaceOrientation:
- (NSUInteger) supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape; (Check for device type here and return appropriate orientations)
}
- (BOOL) shouldAutorotate {
return YES;
}
答案 2 :(得分:0)
你有多少个UIViewController?也许是2,3或更多。
尝试在每个viewcontroller中添加代码
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
NSLog(@"viewcontroller: %@", self);
return YES;
}
您将知道哪个视图控制器采用旋转通知。似乎问题我莫代尔视图控制器。
答案 3 :(得分:0)
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if(toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
// setFrames=CGRectMake(x, y, w, h);
}
答案 4 :(得分:0)
您应该实现所有这些方法,使其适用于所有具有ios&gt; = 4.3版本的设备..
// Autorotation (iOS <= 5.x)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft||interfaceOrientation==UIInterfaceOrientationLandscapeRight||interfaceOrientation == UIInterfaceOrientationPortrait) ;
}
// Autorotation (iOS >= 6.0)
- (BOOL) shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}