Force portrait orientation when the device is in landscape (horizontally flipped) for iOS

Firstly, I looked at many other streams in portrait / landscape orientation for iOS.

I have a hybrid application that is built using IBM Worklight (I am mainly focused on the iOS platform, since I already have a solution for Android that works fine). I added the cordova plugin to access device features. My application should be set to portrait on all screens except one. On one screen (view) I need to maintain a landscape and portrait. However, when I switch to another screen, I need to return only to the portrait, but in my many attempts to stay in the landscape.

I use the techniques supportedInterfaceOrientationsand shouldAutorotateto lock and unlock and switch between support only portrait or landscape and portrait.

Note. My application has only one view controller that contains a webview, so I cannot use solutions to reject and present a modal controller.

I also looked at other topics that mention rotation of power using conversion in iOS, but that doesn't work either. Is there a documented way to set iPhone orientation?

(My app supports iOS7 and above) The only thing that worked for me was

[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];

and

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

However, Apple will reject my application if I use it due to a private api.

Is there any other way to force portrait orientation when the device is rotated to landscape?

+4
2

phonegap ios. ios js .

, count1 = 1, .

HelloworldPlugin.m

#import "HelloworlPlugin.h"

@implementation HelloworlPlugin

int count=0;



-(void)sayhello:(NSMutableArray *)arguments withDict:(NSMutableDictionary *)option
{
    [arguments pop];
    NSString *responseString=[NSString stringWithFormat:@"%@",[arguments objectAtIndex:0]];

 if([responseString isEqualToString:@"1"])
 {
     count=1;
 }
    else
    {
        count=0;
    }
    NSLog(@"Zero %@",responseString);
}

-(int)count1
{
    NSLog(@"count= %d",count);
    if(count<1)
    {

        Cv=0;
    }
    else
    {
        Cv=1;
    }

    NSLog(@"%d",Cv);
    return Cv;


}

@end

MainViewcontroller.h, shouldAutorotateTOInterfaceOrientation, count1 , count1

CDVMainViewController.h

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    HelloworlPlugin *object=[[HelloworlPlugin alloc] init];

    int fValue=[object count1];

    NSLog(@"%d",fValue);
    if(fValue==1)
    {
    return (interfaceOrientation ==UIInterfaceOrientationPortrait);

    }
    else
    {
        return true;
    }
}

clickbutton() - , . 1, , 1 c.

function clickbutton()
{
    cordova.exec(success,failure,"HelloworlPlugin","sayhello",[1]);
}

, .

+1

6.2. suppportedOrientatations appname.plist, . 6.1 , , - .

0

Source: https://habr.com/ru/post/1545066/


All Articles