微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

cordova – 当设备处于横向(水平翻转)时,强制定位到纵向

首先,我已经查看了iOS上强制纵向/横向方向的许多其他主题.

我有一个使用IBM Worklight构建的混合应用程序(我主要关注iOS平台,因为我已经有一个适用于Android解决方案,它工作正常).我添加一个cordova插件来访问设备功能.我的应用程序需要在除一个屏幕之外的所有屏幕上设置为纵向.在一个屏幕(视图)上,我需要支持横向和纵向.然而,当我导航到另一个屏幕时,我只需要恢复到肖像,但在我的许多尝试中,它仍然保持在风景中.

我正在使用supportedInterfaceOrientations和shouldAutorotate方法来锁定&解锁和切换只支持肖像或风景&肖像.

注意:我的应用程序只有一个包含webview的视图控制器,所以我不能使用解决方案来解除和呈现模态视图控制器.

我还在iOS中查看过使用transform进行强制旋转的其他线程,但这似乎也不起作用. Is there a documented way to set the iPhone orientation?

(我的应用支持iOS7及以上版本)
唯一对我有用的是

[UIDevice currentDevice] setorientation:UIInterfaceOrientationPortrait];

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

但是,如果因为私人API而使用这些应用程序,Apple将拒绝我的应用程序.

当设备旋转到横向时,还有其他方法可以强制定位到纵向吗?

解决方法

我知道在ios的phonegap插件中强制定位的一种奇怪方式.我在答案中添加了ios和js代码.

IOS

下面是我用来设置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的值我只在此代码中强制使用portrait,您可以为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()是用于转换为portrait的按钮.在上述目标c编程中,我传递的参数1被设置为count 1.

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

我刚刚给出了一个例子,你可以根据自己的需要进行一点点使用.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐