怎样旋转电脑屏幕控制屏幕旋转

(accidental)
(AmalClooney)
(左右路人甲乙丙)
(橙子大爷)
第三方登录:iOS如何指定某个页面可以旋转屏幕,其余控制器都正常竖屏? - 跟谁学
搜索你想学的科目、老师试试,例如“语文”搜索无锡
&&iOS如何指定某个页面可以旋转屏幕,其余控制器都正常竖屏?需求是这样的: 整个App的大部分界面都是竖屏显示,且只允许竖屏显示。 只有单独几个页面可以切换横竖屏,比如视频播放页面,图片浏览界面。 按照网上的方法试了好久,都没成功,求助!!!DvelSamirChen
参考问题:
我自己搞了搞,写出来一个,但总感觉这样不太科学。。。具体demo在github上:
在AppDelegate.m中- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
if (_allowRotation == 1) {
return UIInterfaceOrientationMaskA
return (UIInterfaceOrientationMaskPortrait);
}}// 支持设备自动旋转- (BOOL)shouldAutorotate{
if (_allowRotation == 1) {
return YES;
return NO;}写这两个方法在你要旋转的controller中一开始的地方写这两句就可以了_appDelegate = (AppDelegate *)[UIApplication sharedApplication]. _appDelegate.allowRotation = 1;在要这个controller要消失的时候 写_appDelegate.allowRotation = 0;就可以了
一开始我也向上面那样设置了,但是后来显示的结果还是不对,虽然界面是竖屏显示,但是整体还是横屏的,状态栏之类的还是在横屏。后来参考了下面的方法解决了://点击按钮旋转到横屏- (void)switchToLandscape{
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIInterfaceOrientationPortrait] forKey:@"orientation"];
//上一句话是防止手动先把设备置为横屏,导致下面的语句失效.
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationLandscapeLeft] forKey:@"orientation"];}//点击返回旋转到竖屏- (void)switchToPortrait{
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationLandscapeLeft] forKey:@"orientation"];
//上一句话是防止手动先把设备置为竖屏,导致下面的语句失效.
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationPortrait] forKey:@"orientation"];}这个我写在了viewController里面,在跳转里面对应设置就好了。其他答案中提到的那2个函数也要对应添加:- (BOOL)shouldAutorotate{
return YES;}- (UIInterfaceOrientationMask)supportedInterfaceOrientations{
if (_isAllowRotation == YES) {
return UIInterfaceOrientationMaskL
return UIInterfaceOrientationMaskP
关于设备的旋转方法,前面两个返回NO,就不支持旋转了,最后一个支持的旋转方向(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return NO;}(BOOL)shouldAutorotate{
return NO;}(UIInterfaceOrientationMask)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskA}董诗磊ios
你是如何解决的
在工程设置里面选择Portrait,就像这样:然后在可以旋转的视图的ViewController里面加上:
override func supportedInterfaceOrientations() -& UIInterfaceOrientationMask {
return .AllButUpsideDown
相关问题大家都在看最新提问
关注我们官方微信关于跟谁学服务支持帮助中心主题 : 整个工程是设置了支持屏幕旋转,那么如何禁止其中某个视图旋转呢?
可可豆: * CB
威望: * 点
在线时间: (时)
注册时间: *
最后登录: *
发自: Web Page
整个工程是设置了支持屏幕旋转,那么如何禁止其中某个视图旋转呢?&&&
如题,整个项目中其他视图都是可以旋转的,但是,现在希望其中一个视图只能保持纵向,不允许旋转。用什么代码有效?在要禁止的视图中,加入了下面的代码,无效。- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{&&&&&&&&return (toInterfaceOrientation == UIInterfaceOrientationPortrait);&&&&}- (BOOL)shouldAutorotate{&&&&&&&&return NO;&&&&}- (NSUInteger)supportedInterfaceOrientations{&&&&&&&&return UIInterfaceOrientationMaskP//只支持这一个方向(正常的方向)&&&&}
级别: 骑士
UID: 159156
可可豆: 1478 CB
威望: 1119 点
在线时间: 890(时)
发自: Web Page
可以自定义编写一个继承自UINavigationController的类,在该类里面可以设置你需要支持的方向。然后在需要的页面将其作为UINavgationController的rootViewController。这样就可以局部设置了
We Can Manage!
可可豆: * CB
威望: * 点
在线时间: (时)
注册时间: *
最后登录: *
发自: Web Page
回 1楼(reylen) 的帖子
我在Stackoverflow上也看到类似解决方法了,但是对于子类化UINavigationController这部分不懂。#import &UINavigationController.h&#import &MonthCalendarVC.h&@implementation UINavigationController (overrides)- (BOOL)shouldAutorotate{&&&&id currentViewController = self.topViewC&&&&if ([currentViewController isKindOfClass:[MonthCalendarVC class]])&&&&&&&&return NO;&&&&return YES;}@end但不是很清楚具体怎么弄。[ 此帖被dingdongdong123在 18:48重新编辑 ]
可可豆: * CB
威望: * 点
在线时间: (时)
注册时间: *
最后登录: *
发自: Web Page
回 1楼(reylen) 的帖子
我单独建了一个UINavigationController 类,系统提示说重复定义了。可能是因为在appDelegate.h中已经原本有一个UINavigationController 的实例。该怎么解决呢?
级别: 骑士
UID: 159156
可可豆: 1478 CB
威望: 1119 点
在线时间: 890(时)
发自: Web Page
创建类MyNavigationController.h文件
#import &UIKit/UIKit.h&
@interface MyNavigationController : UINavigationController
#import &MyNavigationController.h&
@interface MyNavigationController ()
@implementation MyNavigationController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
&&&&self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
&&&&if (self) {
&&&&&&&&// Custom initialization
- (void)viewDidLoad
&&&&[super viewDidLoad];
&&&&// Do any additional setup after loading the view.
- (void)didReceiveMemoryWarning
&&&&[super didReceiveMemoryWarning];
&&&&// Dispose of any resources that can be recreated.
-(BOOL)shouldAutorotate
&&&&return NO;
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
&&&&return NO;
-(NSUInteger)supportedInterfaceOrientations
&&&&return ....(依据需要填写)
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
&&&&return .....(依据需要填写)
We Can Manage!
级别: 精灵王
可可豆: 24890 CB
威望: 25991 点
在线时间: 3387(时)
发自: Web Page
使用自定义的Navigation Controller , 然后present modal view controller 应该是可以的
一直在努力,一直都觉得努力得还不够~~
可可豆: * CB
威望: * 点
在线时间: (时)
注册时间: *
最后登录: *
发自: Web Page
回 4楼(reylen) 的帖子
非常非常感谢,写的非常清楚明了!多谢!
可可豆: * CB
威望: * 点
在线时间: (时)
注册时间: *
最后登录: *
发自: Web Page
回 5楼(wode211) 的帖子
不是很明白,present这部分。
可可豆: * CB
威望: * 点
在线时间: (时)
注册时间: *
最后登录: *
发自: Web Page
回 4楼(reylen) 的帖子
搞定了!多谢。
关注本帖(如果有新回复会站内信通知您)
发帖、回帖都会得到可观的积分奖励。
按"Ctrl+Enter"直接提交
关注CocoaChina
关注微信 每日推荐
扫一扫 关注CVP公众号
扫一扫 浏览移动版}

我要回帖

更多关于 怎样旋转电脑屏幕 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信