iphone定位问题。。

iphone定位问题。。,iphone,ios,uiinterfaceorientation,Iphone,Ios,Uiinterfaceorientation,我遇到了一个关于iphone屏幕方向的问题。我的应用程序的基本sdk是ios 6.0,部署目标是4.3,运行在ios 5.0和5.1上 在应用程序的plist文件中,我设置了纵向(底部主按钮)、横向(左主按钮)和横向(右主按钮)。我正在开发一个通用应用程序。因此,在每个视图的-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation方法中,我有条件地返回iphone的纵向,以

我遇到了一个关于iphone屏幕方向的问题。我的应用程序的基本sdk是ios 6.0,部署目标是4.3,运行在ios 5.0和5.1上

在应用程序的plist文件中,我设置了
纵向(底部主按钮)
横向(左主按钮)
横向(右主按钮)
。我正在开发一个通用应用程序。因此,在每个视图的
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
方法中,我有条件地返回iphone的
纵向
,以及ipad的
横向

我的导航流程是:

UINavigationController
push
uitableviewcontroller
第一个选项卡上有
UINavigationController
pusing在
rootViewController
上逐个显示2个视图

在我的上一个视图中,控制器的
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
方法我返回了
YES
。但该视图的应用程序根本没有被旋转。甚至调用
-(void)都不会将InterfaceOrientation:(UIInterfaceOrientation)旋转到InterfaceOrientation duration:(NSTimeInterval)duration
方法:(

我的要求是只支持一个viewController的横向和纵向方向,而不是整个应用程序


请帮助我。

对于iOS 6,请使用
支持的接口方向
应自动旋转
而不是
应自动旋转指针面方向:

- (NSUInteger) supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape; (Check for device type here and return appropriate orientations)
}

- (BOOL) shouldAutorotate {
   return YES;
}

对于iOS 6,请使用
支持的接口方向
应自动旋转
而不是
应自动旋转指针面方向:

- (NSUInteger) supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape; (Check for device type here and return appropriate orientations)
}

- (BOOL) shouldAutorotate {
   return YES;
}

您有多少个UIViewController?可能是2、3或更多

尝试在每个viewcontroller添加代码

- (BOOL)shouldAutorotateToInterfaceOrientation:    (UIInterfaceOrientation)interfaceOrientation
{
NSLog(@"viewcontroller: %@", self);
return YES;
}

您将知道哪个视图控制器接收旋转通知。模态视图控制器似乎有问题。

您有多少UIViewController?可能是2、3或更多

 -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    if(toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)

  // setFrames=CGRectMake(x, y, w, h);

}
尝试在每个viewcontroller添加代码

- (BOOL)shouldAutorotateToInterfaceOrientation:    (UIInterfaceOrientation)interfaceOrientation
{
NSLog(@"viewcontroller: %@", self);
return YES;
}

您将知道哪个视图控制器接收旋转通知。在模态视图控制器中似乎存在问题。

您可以通过视图控制器类中的此代码解决此方向问题

 -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    if(toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)

  // setFrames=CGRectMake(x, y, w, h);

}
#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)
#定义早于_6的IOS([[[UIDevice currentDevice]systemVersion]floatValue]<6.0)
#将IOS_更新的_或等于_定义为_6([[[UIDevice currentDevice]systemVersion]floatValue]>=6.0)
希望它能起作用


谢谢。

您可以在View Controller类中通过此代码解决此定向问题

#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)
#定义早于_6的IOS([[[UIDevice currentDevice]systemVersion]floatValue]<6.0)
#将IOS_更新的_或等于_定义为_6([[[UIDevice currentDevice]systemVersion]floatValue]>=6.0)
希望它能起作用


谢谢。

您应该实现所有这些方法,使其适用于所有ios>=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;
}
//自动旋转(iOS=6.0)
-(BOOL)应该自动旋转
{
返回YES;
}
-(整数)支持的接口方向
{
返回UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}

您应该实现所有这些方法,使其适用于ios>=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;
}
//自动旋转(iOS=6.0)
-(BOOL)应该自动旋转
{
返回YES;
}
-(整数)支持的接口方向
{
返回UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}

感谢您的友好回复,但应用程序不仅适用于ios6。正如我提到的,我在ios5中运行应用程序,也感谢您的友好回复,但应用程序不仅适用于ios6。正如我提到的,我在ios5中运行应用程序,也适用于ios5。谢谢,但问题是在调用
shouldAutoratate…
后,我返回了我的愿望方向,但应用程序不是ge在那个方向上打电话:(谢谢,但问题是在
shouldAutoratate…
被呼叫后,我返回了我的愿望方向,但应用程序没有进入那个方向:(谢谢,但问题是在
shouldAutoratate…
被呼叫后,我返回了我的愿望方向,但应用程序没有进入那个方向:(这是iOS 6的问题。为此,请看此感谢,但问题是在调用
shouldAutorate…
后,我返回了我的愿望方向,但应用程序没有进入该方向:(这是iOS 6的问题。为此,请看此感谢,但问题是在调用
shouldAutorate…
后,我返回了我的愿望方向,但应用程序没有进入该方向:(谢谢,但问题是在调用
shouldAutorate…
后,我返回了我的愿望方向,但应用程序没有进入该方向:(谢谢,但问题是在调用
shouldAutorate…
后,我返回了我的愿望方向,但应用程序没有进入该方向:(谢谢,但问题是在调用
shouldAutorate…
后,我返回了我的愿望方向,但应用程序没有进入该方向:(