求解,ios7下 setNavigationBarHidden:YES 之后 页面会跟 Statusbar 叠在一起
伊谢尔伦
伊谢尔伦 2017-04-17 11:53:35
[iOS讨论组]

如图

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

全部回复(6)
巴扎黑

这也是困扰我的问题之一。目前我想出了不用AutoLayout时的解决办法:如果用xib的话,请见http://blog.csdn.net/rhljiayou/article/details/12029927;如果不是用xib的话,只能手动偏移了。

#define IOS_7 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0f)
#define IOS6_7_DELTA(V,X,Y,W,H) if (IOS_7) {CGRect f = V.frame;f.origin.x += X;f.origin.y += Y;f.size.width += W;f.size.height += H;V.frame=f;}
...
IOS6_7_DELTA(view, 0, 20, 60, 0);

另外,如果使用了AutoLayout,并且用了StoryBoard,那么可以很方便地将搜索框跟TopLayoutGuide做一个constraint。这个TopLayoutGuide看起来是很有用的,可以看到官方文档里面说的用法。

  • If a status bar is visible onscreen and there is no visible navigation bar, the bottom of the status bar
  • If a navigation bar is visible onscreen, the bottom of the navigation bar
  • If there is no status bar or navigation bar visible onscreen, the top of the screen in the device’s current orientation

但是如果只是用xib的话,似乎没法在IB里面加这个constraint(这个问题见我在stackoverflow上问的问题,但是目前没有解答【大概我的英文太差了?】)。如果是纯代码的话,我对constraints语法不是很熟悉,写的估计是错的,仅供参考:

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSString *verticalConstraint = @"V:|[v]";// for iOS6
    NSMutableDictionary *views = [NSMutableDictionary new];
    NSMutableArray *constraints = [NSMutableArray new];
    [views setObject:self.subview forKey:@"v"];
    if ([self respondsToSelector:@selector(topLayoutGuide)]) {
        // for iOS7
        [views setObject:self.topLayoutGuide forKey:@"topLayoutGuide"];
        verticalConstraint = @"V:[topLayoutGuide][v]";
    }
    [constraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:verticalConstraint options:0 metrics:nil views:views]];
    // ... other constraints
    [self.view addConstraints:constraints];
    // Do any additional setup after loading the view from its nib.
}
ringa_lee

我觉得这是iOS7运行时的问题。所有的view,不管是UINavigationController.view还是UIViewController.viewy值都是0,高度全屏幕(480或568)。不管你有没有NavigationBar,有没有StatusBar,有没有TabBar。 所以,如果非要修复这个问题,需要在viewDidLoad的时候判断view的高度,然后动态set到合适的y和height。

大家讲道理

对,在iOS7中View的高度撑满了屏幕,包括NavBar和TabBar。

天蓬老师

if ([self respondsToSelector:@selector(edgesForExtendedLayout)]) self.edgesForExtendedLayout = UIRectEdgeNone;

PHP中文网

ios7的屏幕坐标0,0点是从statusBar开始的,你可以再xib文件中,顶部留出20像数,然后控件的对齐方式为底部对齐。这样IOS6跟7都可以适应。这个是我能想到的相对简单的版本。如果还又其他的办法的话,可以讨论一下

阿神

1.关于适配navigation

可以重写ViewController的基类,把对的navigation的高度进行判断,如果是iOS7一下nav的高度44,如果iOS7高度则设成64.

2.View的自适应高度

先定义一个iOS7self.view的高度为20,然后动态匹配就行

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号