程序化方向改变对iPhone 5S不起作用

时间:2014-06-02 10:34:48

标签: ios iphone objective-c ios7

该错误与设备和页面方向有关。 我们的应用程序包括具有图形的页面,如果页面包含图形,我们希望页面应旋转到横向左侧。同样,如果页面不包含图表,则页面方向应为纵向。

为了解决这个问题,我们实施了以下代码。

//static bool isRotationEnabled;
//static boundedStatisticsPercentagesNavigationViewController* baseController; // this

//static UIInterfaceOrientation orientationRequest;

+(void)Rotate:(UIInterfaceOrientation)orientation{
    if ( orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationLandscapeLeft) {
        if (baseController.interfaceOrientation != orientation && (int)[[UIDevice currentDevice] orientation] == (int)orientation) {
            isRotationEnabled = YES;
            objc_msgSend([UIDevice currentDevice], @selector(setOrientation:), baseController.interfaceOrientation );
            orientationRequest = orientation;
            [NSTimer scheduledTimerWithTimeInterval:0.1 target:baseController selector:@selector(RotateRequest) userInfo:nil repeats:NO];
        }else{
            isRotationEnabled = YES;
            objc_msgSend([UIDevice currentDevice], @selector(setOrientation:), orientation );
        }
    }
}

-(void)RotateRequest{
    [boundedStatisticsPercentagesNavigationViewController Rotate:orientationRequest];

}

-(BOOL)shouldAutorotate {
    if(isRotationEnabled){
        isRotationEnabled = NO;
        return YES;
    }
    return NO;

}

以上代码适用于IPad,IPod,IPhone4,IPhone5,IPhone5S设备的开发环境。 我们通过app store将我们的应用程序下载到我们的设备 除了IPhone 5S之外,它适用于所有设备。 实际上,这个代码块在以前版本的App中适用于所有设备!

在AppStore中,即使我们在发布发布期间未指定此类内容,也会在兼容性部分中发表评论“此应用针对iPhone 5优化” 发布期间我们的应用可能会发生什么? Apple是否有任何自动应用于App的优化策略?

如果你能帮助我们找到这个问题的原因,我会很感激吗?

2 个答案:

答案 0 :(得分:0)

Apple指南不允许这样做,您无法强迫用户转动手机。但是现在我们可以看到许多应用程序和游戏都可以做到这一点。 所以有一些方法可以做到这一点。您可以根据自己的要求转换视图。

self.view.transform = CGAffineTransformRotate(self.view.transform, -(M_PI / 2.0));

转换程度您可以根据需要决定。

答案 1 :(得分:0)

我更改了代码

objc_msgSend([ UIDevice currentDevice], @selector(setOrientation:), orientation );

用这个

NSMethodSignature *sig = [[UIDevice currentDevice] methodSignatureForSelector:@selector(setOrientation:)];
        NSInvocation* invo = [NSInvocation invocationWithMethodSignature:sig];
        [invo setTarget:[UIDevice currentDevice]];
        [invo setSelector:@selector(setOrientation:)];
        [invo setArgument:&orientation atIndex:2];
        [invo invoke];

我的问题解决了!