1、在iOS11中,导航栏的navigationItem如果是customView,会出现点击事件失效,而在iOS10,即iOS11以下的系统正常。
原因:
这是因为在iOS11中,新的导航视图使用了AutoLayout布局,而我们的给navigationItem设置的customView内部是frame
布局,所以在自动布局下出错了。
解决方案:
针对iOS11,对navigationItem中的customView均采用自动布局,如:
2、在iOS11中,tableView左滑删除按钮的默认样式无效,需实现以下代理方法:
- (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath {
if (@available(iOS 11.0, *)) {
//删除按钮自定义样式
UIContextualAction *deleteRowAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"删除" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
FSMessageListModel *model = self.dataSource[indexPath.row];
[self deleteNotiMessageByType:model.msgId.integerValue index:indexPath];
completionHandler (YES);
}];
deleteRowAction.image = [UIImage imageNamed:@"msg_delete"];
deleteRowAction.backgroundColor = RGBA(228, 67, 46, 1);
UISwipeActionsConfiguration *config = [UISwipeActionsConfiguration configurationWithActions:
@[deleteRowAction]];
return config;
} else {
// Fallback on earlier versions
return nil;
}
}
3、iOS11废弃了automaticallyAdjustsScrollViewInsets属性,需要使用scrollview的contentInsetAdjustmentBehavior属性。
if (@available(iOS 11.0, *)) {
self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
} else {
// Fallback on earlier versions
}
更多iOS11和iPhone X的适配可以参考:
https://www.jianshu.com/p/370d82ba3939
http://www.cocoachina.com/ios/20171011/20737.html