欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

詳解iOS11關(guān)于導(dǎo)航欄問(wèn)題

 更新時(shí)間:2017年10月21日 08:29:35   作者:h_wen  
本篇文章主要介紹了詳解iOS11關(guān)于導(dǎo)航欄問(wèn)題,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

前言

iOS11導(dǎo)航欄除了新加入了largeTitles和searchController兩個(gè)新特性,可能是加入largeTitles的原因其結(jié)構(gòu)較iOS 10發(fā)生了些變化。

iOS11之前導(dǎo)航欄的navigationBarButton則直接添加在navigationBar上面

在iOS11之后,蘋(píng)果添加了新的類(lèi)來(lái)管理,可以看到titleView直接加在_UINavigationBarContentView上,UIBarButtonItem則添加在_UIButtonBarStackView上面,而_UIButtonBarStackView則添加在_UINavigationBarContentView上面,最后添加到UINavigationBar上面,如下圖所示:

由于結(jié)構(gòu)的變化,在iOS 11中我們自定義設(shè)置leftBarButtonItem,其點(diǎn)擊區(qū)域變得很小,讓人點(diǎn)的很焦灼,如下圖綠色區(qū)域所示:


具體代碼如下,設(shè)置的frame在這里并沒(méi)有什么卵用,點(diǎn)擊區(qū)域依然只有圖片原本的size那么大:

    UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 60, 40)];
    [btn setImage:imageWhite forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(bpBack) forControlEvents:UIControlEventTouchUpInside];
    btn.backgroundColor = [UIColor greenColor];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
    leftItem.width = 60;
    self.navigationItem.leftBarButtonItem = leftItem;

為了能增加點(diǎn)擊區(qū)域,我們就需要增加button的size,然后就想到通過(guò)改變ContentEdgeInsets來(lái)增大button的size,

... 
...
 btn.backgroundColor = [UIColor greenColor];
 if (@available(iOS 11.0,*)) {
     [btn setContentMode:UIViewContentModeScaleToFill];
     [btn setContentEdgeInsets:UIEdgeInsetsMake(0, 5, 5, 20)];
  }
 UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
...
...

另:searchBar設(shè)置為titleview,會(huì)導(dǎo)致navigation的高度發(fā)生異常(ps:push到下一個(gè)界面,下個(gè)界面的view距離navigation出現(xiàn)了一段黑色區(qū)域)需要處理下:

  CGRect frame = CGRectMake(0, 0, 150, 44);
  UISearchBar *search = [[UISearchBar alloc] initWithFrame:frame];
  search.placeholder = @"搜索";
  search.delegate = self;
  UITextField *searchField=[search valueForKey:@"_searchField"];
  searchField.backgroundColor = [UIColor groupTableViewBackgroundColor];
// --- iOS 11異常處理
  if(@available(iOS 11.0, *)) {
    [[search.heightAnchor constraintEqualToConstant:44] setActive:YES];
  }
  self.navigationItem.titleView = search;

詳細(xì)資料參考:
https://stackoverflow.com/questions/45997996/ios-11-uisearchbar-in-uinavigationbar

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論