iOS怎样在横屏时不隐藏ios 状态栏强制横屏

   MPMoviePlayerViewController *moviePlayerViewController = [[MPMoviePlayerViewController alloc] init];
moviePlayerViewController.view.frame = CGRectMake(0, 0, self.view.bounds.size.height, self.view.bounds.size.width);
moviePlayerViewController.view.center = CGPointMake(self.view.bounds.size.width/2, self.view.bounds.size.height/2);
CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI/2);
[moviePlayerViewController.view setTransform:transform];
[self.view addSubview:moviePlayerViewController.view];
如果需要放大可以设置&moviePlayerViewController.scalingMode 属性,有4种可选。
你会发现系统状态栏会随着屏幕旋转,这时候最好的方法是将其隐藏
在viewWillAppear:里[[UIApplication sharedApplication] setStatusBarHidden:YES];
viewDidDisappear:里[[UIApplication sharedApplication] setStatusBarHidden:NO];
阅读(...) 评论()求大家帮忙看下为什么我横屏就状态栏出现【ios8吧】_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:237,292贴子:
求大家帮忙看下为什么我横屏就状态栏出现收藏
如图该咋办
处女星号邮轮由上海出发前往日本,畅享日本自然美景和饕餮美食
不要开屏幕锁定
那个锁那个、
贴吧拳王争霸赛中累计获取10场胜利,
登录百度帐号推荐应用
为兴趣而生,贴吧更懂你。或匿名用户不能发表回复!|
每天回帖即可获得10分可用分!小技巧:
你还可以输入10000个字符
(Ctrl+Enter)
请遵守CSDN,不得违反国家法律法规。
转载文章请注明出自“CSDN(www.csdn.net)”。如是商业用途请联系原作者。> 博客详情
摘要: 在处理界面的强制横屏问题时,新手可能会遇到许多问题,这里为大家提供几种方案。
IOS6以后,若想在项目中支持横屏,我们首先需要在plist文件中添加支持横屏的设置,否则有些代码设置将会失效。
有来那个方式设置:
1、在pilist的Supported interface orientations 字段中添加
2、在Xcode的设置中勾选
现在我们来看决定屏幕方向的几个函数:
在IOS6之前,我们只需通过一个函数
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { &&& return (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight); }
就可以支持指定控制器的旋转。通过新的文档,我们可以看到:
//&Applications&should&use&supportedInterfaceOrientations&and/or&shouldAutorotate..
-&(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
&&&&&NS_DEPRECATED_IOS(2_0,&6_0);
//这个方法在6.0之后被标记为过时的
我们通过下面两个方法来代替:
//是否允许屏幕旋转
-(BOOL)shouldAutorotate{ &&& return YES; } //支持的方向 - (NSUInteger)supportedInterfaceOrientations { &&& return UIInterfaceOrientationMaskLandscapeR } 这是个枚举
typedef&NS_OPTIONS(NSUInteger,&UIInterfaceOrientationMask)&{
&&&&UIInterfaceOrientationMaskPortrait&=&(1&&&&UIInterfaceOrientationPortrait),
&&&&UIInterfaceOrientationMaskLandscapeLeft&=&(1&&&&UIInterfaceOrientationLandscapeLeft),
&&&&UIInterfaceOrientationMaskLandscapeRight&=&(1&&&&UIInterfaceOrientationLandscapeRight),
&&&&UIInterfaceOrientationMaskPortraitUpsideDown=(1&&&&UIInterfaceOrientationPortraitUpsideDown),
&&&&UIInterfaceOrientationMaskLandscape&=&(UIInterfaceOrientationMaskLandscapeLeft&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&|&UIInterfaceOrientationMaskLandscapeRight),
&&&&UIInterfaceOrientationMaskAll&=&(UIInterfaceOrientationMaskPortrait&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&|&UIInterfaceOrientationMaskLandscapeLeft
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&|&UIInterfaceOrientationMaskLandscapeRight&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&|&UIInterfaceOrientationMaskPortraitUpsideDown),
&&&&UIInterfaceOrientationMaskAllButUpsideDown&=&(UIInterfaceOrientationMaskPortrait&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&|&UIInterfaceOrientationMaskLandscapeLeft&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&|&UIInterfaceOrientationMaskLandscapeRight),
通过这两个函数,如果我们需要某个控制器强制方向,我们可以设置支持单一的方向,即可达到目的。
如果你们项目中的RootViewController是导航,你会发现,你在Push出来的视图中添加刚才的代码并没有起作用,原因是导航,并没有进行设置,我们创建一个文件,继承于NavigationController。在里面重写刚才的方法,这么做后,屏幕确实横了过来,并且这个导航push的所有子界面都将横屏,这也不是我们想要的效果。我们想自由的控制每个push出来的界面的屏幕方向,可以在导航里这么做:
-(BOOL)shouldAutorotate{
&&&&return&[self.topViewController&shouldAutorotate];
//支持的方向
-&(NSUInteger)supportedInterfaceOrientations&{
&&&&return&[self.topViewController&supportedInterfaceOrientations];;
我们还需要做一些处理,经过我的测试,导航必须在pop后才会重新调用这些函数,所以我的方法是这样做:弹出一个中间控制器后再POP回来
@implementation&ViewController2
-&(void)viewDidLoad&{
&&&&[super&viewDidLoad];
&&&&//&Do&any&additional&setup&after&loading&the&view.
&&&&[self.navigationController&pushViewController:[[ViewController3&alloc]init]&animated:YES];
@implementation&ViewController3
-&(void)viewDidLoad&{
&&&&[super&viewDidLoad];
&&&&//&Do&any&additional&setup&after&loading&the&view.
&&&&[self.navigationController&popViewControllerAnimated:YES];
这样做,我们就可以自由的控制每个视图控制器的方向了。
同理,如果根视图控制器是tabBar,则我们需要在tabBar中做操作。
如果我们大多是的视图控制器都是一个方向的,只有偶尔的几个会不同,这时候,我们其实可以采取presentationController的方式,然后直接在弹出的控制器中写那两个方法即可。这是最简单的途径了。
专注技术,热爱生活,交流技术,也做朋友。
——珲少 QQ群:
人打赏支持
码字总数 381092
支付宝支付
微信扫码支付
打赏金额: ¥
已支付成功
打赏金额: ¥

我要回帖

更多关于 ipad横屏状态栏psd 的文章

 

随机推荐