怎样使时间状态栏ios 横屏显示状态栏 ios

Pages: 1/2
主题 : 自定义状态栏,转换成横屏时候的处理
级别: 侠客
可可豆: 613 CB
威望: 613 点
在线时间: 168(时)
发自: Web Page
自定义状态栏,转换成横屏时候的处理&&&
如题,小弟需要实现一个类似新浪微博客户发完微博后,最上面状态栏那个提示,在网上找了个例子,很不错的,已经可以用了,但是发现在横屏的时候呢,UIwindow无法进行旋转,导致自定义状态栏一直停留在竖屏状态,已上传代码附件,希望可以一起探讨解决,感觉这个效果挺好的
图片:763FC148-78C9--D0E8FBE8C78D.png
(117 K) 下载次数:105
级别: 新手上路
可可豆: 1 CB
威望: 1 点
在线时间: 3(时)
发自: Web Page
// 初始化一个状态条级别的window&&&&CGRect frame = CGRectMake(0.0, 0.0, 320.0, 20.0);&&&&UIWindow* statusbarWindow = [[UIWindow alloc] initWithFrame:frame];&&&&[statusbarWindow setBackgroundColor:[UIColor clearColor]];&&&&[statusbarWindow setWindowLevel:UIWindowLevelStatusBar];&&&&&&&&// 添加自定义子视图&&&&UIView *customView = [[UIView alloc] initWithFrame:frame];&&&&// ...(各种对视图的定制)&&&&[statusbarWindow addSubview:customView];&&&&[statusbarWindow makeKeyAndVisible];你可以试试这个,不知道行不行,不过我的类似问题解决了。。。
级别: 骑士
可可豆: 3521 CB
威望: 3517 点
在线时间: 910(时)
发自: Web Page
这种应用可以上appstore?&&苹果不是禁止custom status bar 外观的吗?
soho社区:http://www.sohoin.com个人博客:http://blog.csdn.net/favormm
级别: 新手上路
可可豆: 42 CB
威望: 22 点
在线时间: 156(时)
发自: Web Page
你好,你的问题解决的,现在我也遇到这个问题了
级别: 圣骑士
可可豆: 1680 CB
威望: 1825 点
在线时间: 853(时)
发自: Web Page
custom status bar 是可以过审核的,貌似 最好不要程序在前台的时候一直覆盖系统状态栏, 或者只覆盖一部分, appstore 有很多应用这样做的,楼主问题在于没处理横屏时调用那个函数,在那个函数里对对custom status bar 重新设置下frame
I will change to pythoner
级别: 侠客
可可豆: 613 CB
威望: 613 点
在线时间: 168(时)
发自: Web Page
可以添加对状态栏的监控通知,然后在设备旋转的时候,旋转状态栏:&&&&&&&&[[NSNotificationCenter defaultCenter] addObserver:self&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& selector:@selector(didChangeStatusBarFrame:)&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& name:UIApplicationWillChangeStatusBarFrameNotification object:nil];然后在函数内写改变状态栏frame的方法
级别: 侠客
可可豆: 613 CB
威望: 613 点
在线时间: 168(时)
发自: Web Page
对了,改变frame时需要先self.transform = CGAffineTransformMakeRotation(pi * (-90.f) / 180.0f);,这个角度4个方向不一样
级别: 圣骑士
UID: 21430
可可豆: 2237 CB
威望: 2110 点
在线时间: 626(时)
发自: Web Page
楼主不错啊,解决后再回来解答
“编程的时候,总是想着那个维护你代码的人会是一个知道你住在哪儿的有暴力倾向的精神病患者。”—— Martin Golding
级别: 圣骑士
UID: 116335
可可豆: 2981 CB
威望: 2882 点
在线时间: 265(时)
发自: Web Page
&&&&&&&&&&
级别: 骑士
可可豆: 1444 CB
威望: 1444 点
在线时间: 308(时)
发自: Web Page
多谢楼主,楼主正解
Pages: 1/2
关注本帖(如果有新回复会站内信通知您)
发帖、回帖都会得到可观的积分奖励。
按"Ctrl+Enter"直接提交
关注CocoaChina
关注微信 每日推荐
扫一扫 关注CVP公众号
扫一扫 浏览移动版在 SegmentFault,学习技能、解决问题
每个月,我们帮助 1000 万的开发者解决各种各样的技术问题。并助力他们在技术能力、职业生涯、影响力上获得提升。
问题对人有帮助,内容完整,我也想知道答案
问题没有实际价值,缺少关键内容,没有改进余地
App中其它界面都是竖屏, 只有一个界面是需要横屏的, 怎样使这个界面强制横屏布局?
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
如果需要特定ViewController旋转, 可以为UINavigationController添加Category(类目)UINavigationController+InterfaceOrientation, 然后在指定的ViewController中调用即可.
@implementation UINavigationController (InterfaceOrientation)
- (BOOL)shouldAutorotate
if ([self.topViewController respondsToSelector:@selector(shouldAutorotate)]) {
return [self.topViewController shouldAutorotate];
return NO;
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
if ([self.topViewController respondsToSelector:@selector(supportedInterfaceOrientations)]) {
return [self.topViewController supportedInterfaceOrientations];
return [super supportedInterfaceOrientations];
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
if ([self.topViewController respondsToSelector:@selector(preferredInterfaceOrientationForPresentation)]) {
return [self.topViewController preferredInterfaceOrientationForPresentation];
return [super preferredInterfaceOrientationForPresentation];
另外, 推荐一篇博文:
对于不同级别的屏幕旋转梳理的较为清晰.
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
使用如下这种方式,在需要横屏的页面添加。
- (NSUInteger)supportedInterfaceOrientations
return UIInterfaceOrientationMaskL
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
那怎么保证其它界面始终是竖屏呢
该答案已被忽略,原因:
同步到新浪微博
分享到微博?
关闭理由:
删除理由:
忽略理由:
推广(招聘、广告、SEO 等)方面的内容
与已有问题重复(请编辑该提问指向已有相同问题)
答非所问,不符合答题要求
宜作评论而非答案
带有人身攻击、辱骂、仇恨等违反条款的内容
无法获得确切结果的问题
非开发直接相关的问题
非技术提问的讨论型问题
其他原因(请补充说明)
我要该,理由是:
在 SegmentFault,学习技能、解决问题
每个月,我们帮助 1000 万的开发者解决各种各样的技术问题。并助力他们在技术能力、职业生涯、影响力上获得提升。ios-iOS怎样在横屏时不隐藏状态栏
作者:用户
浏览:951 次
iOS怎样在横屏时不隐藏状态栏有一个播放界面是横屏的,想让它显示状态栏怎么实现,现在旋转到横屏时自动隐藏了状态栏,怎么不让它自动隐藏iOS显示启动页时隐藏状态栏--------------------
iOS怎样在横屏时不隐藏状态栏
有一个播放界面是横屏的,想让它显示状态栏 怎么实现,现在旋转到横屏时自动隐藏了状态栏,怎么不让它自动隐藏
解决方案二:
因为 状态栏设置的时候 ,只是针对竖屏(正常情况下的),如上图所示
底部的wAny hAny
在storyboard里可以调整在哪种屏幕下显示什么按钮,状态栏
解决方案三:
你试一下这2个属性
【云栖快讯】新手小白必看!编程语言系列讲座火爆进行中,与行业资深专家一起学习Python、C++、JavaScript、Java!从入门到进阶&&
弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率
40+云计算产品,6个月免费体验
稳定可靠、可弹性伸缩的在线数据库服务,全球最受欢迎的开源数据库之一
云服务器9.9元/月,大学必备怎样使时间状态栏横屏显示 ios_百度知道
怎样使时间状态栏横屏显示 ios
我有更好的答案
解决方法:在plist文件中将 View controller-based status bar appearance 设置为NO
在application:didFinishLaunchingWithOptions:中添加下面代码[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
【0元入学,两周免费试听】
主营:培训【Python+人工智能,Java大数据,HTML5】
为您推荐:
其他类似问题
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。最近有一个项目,例如:A界面跳转到B界面,A界面是竖屏的,B界面进入就要横屏。
花了半天的时间在网上搜索解决方案,有些论坛的大牛也就贴两行代码,具体实现也没有,对我们这种菜鸟造成一万点真实伤害。为了避免后人在浪费时间,在这里我整理一下,并且上传Demo到GitHub。在iOS7 8 9 上运行都OK.
在这里我整理了3种解决方案。
原文地址:http://www.cnblogs.com/niit-soft-518/p/5611298.html&
使用&presentViewController
1.首先设置项目 支持的屏幕方向
2.写一个子类CusNavigationController 继承&UINavigationController,在CusNavigationController中重写方法:shouldAutorotate 和&supportedInterfaceOrientations
1 @implementation CusNavViewController
3 - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
8 - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
13 //支持旋转
14 -(BOOL)shouldAutorotate{
return [self.topViewController shouldAutorotate];
18 //支持的方向
19 - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return [self.topViewController supportedInterfaceOrientations];
在AppDelegate中设置RootViewController
1 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
[self.window makeKeyAndVisible];
ViewController *vc
=[[ViewController alloc]init];
CusNavViewController *nav = [[CusNavViewController alloc]initWithRootViewController:vc];
[self.window setRootViewController:nav];
return YES;
3.最重要的来咯,界面A中,重写旋转方法 和 支持的方向
1 //支持旋转
2 -(BOOL)shouldAutorotate{
return YES;
6 //支持的方向 因为界面A我们只需要支持竖屏
7 - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskP
4.界面A跳转界面B的方法:
1 -(void)pushaction{
ViewControllertwo *vc = [[ViewControllertwo alloc]init];
//使用 presentViewController 跳转
[self presentViewController:vc animated:YES completion:nil];
5.界面B重写 旋转方法 和 支持的方向
1 //支持旋转
2 -(BOOL)shouldAutorotate{
return YES;
6 //支持的方向
7 - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscapeL
11 //一开始的方向
12 -(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return UIInterfaceOrientationLandscapeL
GitHub Demo地址:https://github.com/zhuxinleibandou/-Demo
&原文地址:http://www.cnblogs.com/niit-soft-518/p/5611298.html
使用方案一presentViewController确实很不错,但是毕竟也有些不方便,如果想用在界面使用Nav &push到别的界面就不太好实现了,所以,我又找了半天,又找到了解决方案。
1.设置项目支持的旋转方向:
2.创建子类CusNavViewController 继承UINavigationController
3.界面A设置支持的方向 和 是否可以旋转
1 //是否可以旋转
2 - (BOOL)shouldAutorotate
return false;
6 //支持的方向
7 -(UIInterfaceOrientationMask)supportedInterfaceOrientations
return UIInterfaceOrientationMaskP
4.push进去的界面B 设置 方向 和 旋转
1 //支持的方向
2 -(UIInterfaceOrientationMask)supportedInterfaceOrientations
return UIInterfaceOrientationMaskLandscapeL
7 //是否可以旋转
8 -(BOOL)shouldAutorotate
return YES;
5.界面B设置物理设备方向:
//setOrientation 在3.0以后变为私有方法了,不能直接去调用此方法,否则后果就是被打回。在网上搜了很多很久,都是这种调用私有方法的://强制横屏,会被打回。if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {[[UIDevice currentDevice] performSelector:@selector(setOrientation:)withObject:(id)UIInterfaceOrientationLandscapeRight];}
不能直接调用,但是可以间接的去调用,下面的方法就是利用 KVO机制去间接调用,多次验证不会被打回,放心!-(void)viewWillAppear:(BOOL)animated{
NSNumber *orientationUnknown = [NSNumber numberWithInt:UIInterfaceOrientationUnknown];
[[UIDevice currentDevice] setValue:orientationUnknown forKey:@"orientation"];
NSNumber *orientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
[[UIDevice currentDevice] setValue:orientationTarget forKey:@"orientation"];
这里不是直接使用苹果的私有变量,而是利用kvo的方法 间接的调用此方法,可以上架,不会被打回。
至于这里为什么要 多写这两行代码:
NSNumber *orientationUnknown = [NSNumber numberWithInt:UIInterfaceOrientationUnknown];
[[UIDevice currentDevice] setValue:orientationUnknown forKey:@"orientation"];
请参考博客:http://www.jianshu.com/p/6c45fa2bb970
*iOS中可以直接调用某个对象的消息方式有两种
*1.performSelector:withO
&*2.NSInvocation
1 //使用这里的代码也是oK的。 这里利用 NSInvocation 调用 对象的消息
2 - (void) viewWillAppear:(BOOL)animated
[super viewWillAppear:animated];
if([[UIDevice currentDevice]respondsToSelector:@selector(setOrientation:)]) {
SEL selector = NSSelectorFromString(@"setOrientation:");
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];
[invocation setSelector:selector];
[invocation setTarget:[UIDevice currentDevice]];
int val = UIInterfaceOrientationLandscapeL//横屏
[invocation setArgument:&val atIndex:2];
[invocation invoke];
第一个参数需要接收一个指针,也就是传递值的时候需要传递地址
第二个参数:需要给指定方法的第几个参数传值
注意:设置参数的索引时不能从0开始,因为0已经被self(target)占用,1已经被_cmd(selector)占用在NSInvocation的官方文档中已经说明
(_cmd在Objective-C的方法中表示当前方法的selector,正如同self表示当前方法调用的对象实例。)
[invocationsetArgument:&valatIndex:2];
调用NSInvocation对象的invoke方法*只要调用invocation的invoke方法,就代表需要执行NSInvocation对象中制定对象的指定方法,并且传递指定的参数
[invocationinvoke];
关于NSInvocation的博客
方法一GitHub地址:
方法二 和 方法三 的GitHub地址:
&原文地址:http://www.cnblogs.com/niit-soft-518/p/5611298.html
阅读(...) 评论()}

我要回帖

更多关于 ios横屏后状态栏消失 的文章

更多推荐

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

点击添加站长微信