gpt4 book ai didi

cordova - 对于 iOS,当设备处于横向(水平翻转)时强制方向为纵向

转载 作者:行者123 更新时间:2023-12-02 12:00:00 24 4
gpt4 key购买 nike

首先,我查看了许多有关 iOS 强制纵向/横向方向的其他主题。

我有一个使用 IBM Worklight 构建的混合应用程序(我主要关注 iOS 平台,因为我已经有一个运行良好的 Android 解决方案)。我添加了一个 cordova 插件来访问设备功能。我的应用程序需要在除一个屏幕之外的所有屏幕上设置为纵向。在一个屏幕( View )上,我需要支持横向和纵向。但是,当我导航到另一个屏幕时,我只需要恢复为纵向,但在我的多次尝试中,它保持横向。

我使用 supportedInterfaceOrientationsshouldAutorotate 方法来锁定和解锁以及在仅支持纵向或横向和纵向之间切换。

注意:我的应用程序只有一个包含 Web View 的 View Controller ,因此我无法使用解决方案来关闭并呈现模态视图 Controller 。

我还查看了其他线程提到在 iOS 中使用变换进行强制旋转,但这似乎也不起作用。 Is there a documented way to set the iPhone orientation?

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

[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];

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

但是,如果我因为私有(private) 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的值,我在此代码中强制仅纵向,您可以为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在上面的objective c编程中被设置为计数1。

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

我刚刚给出了一个例子,你可以放大一点,根据你的需要使用。

关于cordova - 对于 iOS,当设备处于横向(水平翻转)时强制方向为纵向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24285268/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com