[適配] iOS 10 Safe Area

現象

Push Storyboard按鈕事件Push到最後一個頁面。 Back Button先從Tab Bar(此時已經隱藏了)的頂部,而後回到底部。 用爲代碼描述,大概是經歷了ios

back.bottomConstraint.constant = -tabbarHeight;
back.bottomConstraint.constant = 0.0f;
複製代碼

環境

  • iOS 10.3.3
  • Storyboard佈局
  • 視圖層級

  • 最後一頁,Back Button佈局

  • Hide Bottom Bar on Push: YES

緣由

這裏是他們的看法bash

這裏發現一個和我同樣的問題,很早了,我給了答案ide

Safe AreaiOS 11的特性,對iOS 10支持得不太好(< iOS 11估計都有問題),須要作適配。佈局

但奇怪的是,我還沒發現Safe Area Top須要適配,顯然Safe Area Bottom須要。ui

解決辦法

底部約束Safe Area都改爲Superview atom

而後綁定約束爲屬性,代碼適配,代碼像這樣spa

@interface YourViewController ()

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomConstraint;

@end

@implementation YourViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    CGFloat bottomValue = 0.0f; // your value
    UIEdgeInsets edgeInsets = UIApplication.sharedApplication.keyWindow.layoutMargins;
    CGFloat bottomInset = edgeInsets.bottom;
    self.bottomConstraint.constant = - bottomInset - bottomValue;
}
@end
複製代碼

爲何

爲啥不用直接Storyboard適配,由於Storyboard沒辦法搞這種適配,多是我沒找到,有的話告訴我❤️code

相關文章
相關標籤/搜索