1.UITableView自動計算內邊距
在ios11上沒有導航欄的tableView上下會各多處一塊區域,類似于這樣
是因為在ios11上UIScrollView的屬性contentInsetAdjustmentBehavior默認是UIScrollViewContentInsetAdjustmentAutomatic會自動計算內邊距。
把它設成UIScrollViewContentInsetAdjustmentNever就好了,因為這個值是ios11才有的,所以要寫成
if (@available(iOS 11.0, *)) {
_tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
2.導航欄按鈕偏移
之前因為不希望導航欄的按鈕太貼近邊緣所以通過設了一個空的UIBarbuttonItem來使導航欄按鈕和邊緣空隙加大:
UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
target:nil action:nil];
negativeSpacer.width = -9;
self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:negativeSpacer, _leftBackItem, nil];
但是在ios11上失效了,為了達到同樣的效果,我就使用UIButton上的contentEdgeInsets和imageEdgeInsets屬性將內容和圖片做偏移:
UIButton *leftButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
[leftButton setImage:[UIImage imageNamed:@"ic_back"] forState:UIControlStateNormal];
leftButton.contentEdgeInsets = UIEdgeInsetsMake(0, -9,0, 0);
leftButton.imageEdgeInsets = UIEdgeInsetsMake(0, -9, 0, 0);
[leftButton addTarget:self action:@selector(clickLeftItemForBack:) forControlEvents:UIControlEventTouchUpInside];
_leftBackItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
右邊的按鈕同理,具體偏移的大小根據自己的需要更改。
3.UISearchBar大小變化
UISearchBar和UISwitch控件一樣,高度是固定的,之前都是44,ios11上的高度變成了56。