简体   繁体   中英

programmatic orientation change does not work for IPhone 5S

The bug is about the device and page orientation. Our app includes pages which have graphics and we would like that if the page includes a graphic, page should be rotated to Landscape Left. Similarly, if the page does not include a graph, the page orientation should be Portrait.

To handle this, we implemented the code below.

//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;

}

the code above works well in development environment for IPad, IPod, IPhone4,IPhone5,IPhone5S devices. We downloaded our app via app store to our devices. It worked on all devices EXCEPT IPhone 5S. Actually, this code block was working properly in previous version of our App for all devices!

In AppStore, there is a comment in compatibility section that says “this app optimized for iPhone 5” even if we did not specify such kind of thing during publishing the release … What might have happened to our app during release? Does Apple have any optimizations policies that are automatically applied on App?

I'd appreciate if you could help us find the cause of this problem?

The Apple guideline doesn't allow that, you can't force your user to turn his phone. But these days we can see many of app and Games that does this. So there some ways to do that. You can transform your view according to your requirement.

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

degree of transform you could decide as per you need.

I changed the code

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

with this

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];

And my problem is solved!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM