如何动态锁定ios本机应用程序的方向

如何动态锁定ios本机应用程序的方向,ios,Ios,我对IOS中的Objective c本机编码还不熟悉。我有两个按钮。一个用于将应用程序锁定为纵向,另一个用于锁定横向。我应该怎么做才能做到这一点。锁定的意思是它将固定在锁定的一侧,并且不会转动。例如: [[UIApplication sharedApplication] setStatusBarOrientation:UIDeviceOrientationLandscapeLeft animated:NO]; 是的,我已经使用我在worklight(混合应用程序)中创建的ios插件实现

我对IOS中的Objective c本机编码还不熟悉。我有两个按钮。一个用于将应用程序锁定为纵向,另一个用于锁定横向。我应该怎么做才能做到这一点。锁定的意思是它将固定在锁定的一侧,并且不会转动。

例如:

    [[UIApplication sharedApplication] setStatusBarOrientation:UIDeviceOrientationLandscapeLeft animated:NO];

是的,我已经使用我在worklight(混合应用程序)中创建的ios插件实现了相同的方法

设置标志的功能是

#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
是一个默认函数,根据它设置方向返回true设置所有方向,通过给出适当的方向,我们可以设置答案。因此,根据我存储在fValue中的cv值,我锁定了方向

- (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;
    }
}

shouldAutorotateToInterfaceOrientation