大佬教程收集整理的这篇文章主要介绍了cordova – 当设备处于横向(水平翻转)时,强制定位到纵向,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个使用IBM Worklight构建的混合应用程序(我主要关注iOS平台,因为我已经有一个适用于Android的解决方案,它工作正常).我添加了一个cordova插件来访问设备功能.我的应用程序需要在除一个屏幕之外的所有屏幕上设置为纵向.在一个屏幕(视图)上,我需要支持横向和纵向.然而,当我导航到另一个屏幕时,我只需要恢复到肖像,但在我的许多尝试中,它仍然保持在风景中.
我正在使用supportedInterfaceOrientations和shouldAutorotate方法来锁定&解锁和切换只支持肖像或风景&肖像.
注意:我的应用程序只有一个包含webview的视图控制器,所以我不能使用解决方案来解除和呈现模态视图控制器.
我还在iOS中查看过使用transform进行强制旋转的其他线程,但这似乎也不起作用. Is there a documented way to set the iPhone orientation?
[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPorTrait];
和
objc_msgSend([UIDevice currentDevice],@SELEctor(setOrientation:),UIInterfaceOrientationPorTrait );
但是,如果因为私人API而使用这些应用程序,Apple将拒绝我的应用程序.
当设备旋转到横向时,还有其他方法可以强制定位到纵向吗?
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]); }
我刚刚给出了一个例子,你可以根据自己的需要进行一点点使用.
以上是大佬教程为你收集整理的cordova – 当设备处于横向(水平翻转)时,强制定位到纵向全部内容,希望文章能够帮你解决cordova – 当设备处于横向(水平翻转)时,强制定位到纵向所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。