这两天对自己负责的项目进行iOS 11和iPhone X的适配,网上的博客很多,也看了很多别人的记录博客,这里把自己遇到的问题记录下,当然有些不仅仅是iOS 11和iPhone X的适配,还包括自己遇到的问题和解决方法。

1> iOS Assertion failure in -[UITableView _classicHeightForRowAtIndexPath:]:

这问题是由于cell高度负数导致,去看看:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { }

2> iOS 11使用第三方侧滑Cell-MSCMoreOptionTableViewCell,不能出现多个按钮:

https://github.com/scheinem/MSCMoreOptionTableViewCell/issues/37

 

https://forums.developer.apple.com/thread/86009

具体代码如下:

-(id)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath {
return [self getRowActions:tableView indexPath:indexPath];
} -(id)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
return [self getRowActions:tableView indexPath:indexPath];
} -(id)getRowActions:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath {
if (@available(iOS , *)) {
UIContextualAction *delete = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive
title:@"删除"
handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
completionHandler(YES);
}];
delete.backgroundColor = [UIColor redColor];
UIContextualAction *modify = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive
title:@"修改"
handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
completionHandler(YES);
}];
modify.backgroundColor = [UIColor redColor];
UISwipeActionsConfiguration *swipeActionConfig = [UISwipeActionsConfiguration configurationWithActions:@[delete, modify]];
swipeActionConfig.performsFirstActionWithFullSwipe = NO;
return swipeActionConfig;
}
return nil;
}

当然你可以使用iOS 8自带的侧滑Cell出现多个按钮,这里因为之前项目适配iOS 7,懒得改了,代码如下:

- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
// 添加一个删除按钮
UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"删除"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
[self tableView:tableView moreOptionButtonPressedInRowAtIndexPath:indexPath];
}]; // 添加一个修改按钮
UITableViewRowAction *modifyRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"修改"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
[self tableView:tableView moreOptionButtonPressedInRowAtIndexPath:indexPath];
}];
modifyRowAction.backgroundEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
return @[modifyRowAction, deleteRowAction];
}

3> iOS 11TableView的sectionHeader高度变大:实现返回View的代理即可。

#pragma mark - talbeView delegate

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return .f;
} - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 0.1f;
} // 解决iOS 11 sectionHeader高度变高的问题
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { return [UIView new];
} - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { return [UIView new];
}

4> 添加下面的代码,会造成系统选择相册顶部偏移:

//    //解决iOS11,仅实现heightForHeaderInSection,没有实现viewForHeaderInSection方法时,section间距大的问题
// [UITableView appearance].estimatedRowHeight = 0;
// [UITableView appearance].estimatedSectionHeaderHeight = 0;
// [UITableView appearance].estimatedSectionFooterHeight = 0;
//
// //iOS11 解决SafeArea的问题,同时能解决pop时上级页面scrollView抖动的问题
// if (@available(iOS 11, *)) {
// [UIScrollView appearance].contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; //iOS11 解决SafeArea的问题,同时能解决pop时上级页面scrollView抖动的问题
// }

5> iOS 11 SearchBar的高度变化:

#define iOS(version) ([[UIDevice currentDevice].systemVersion doubleValue] >= version)
#define K_SEARCH_BAR_HEIGHT (iOS(11)?56.f:44.f)

有博客说可以这样:我好像试了没什么效果

// 强制高度:
[self.searchBar.heightAnchor constraintLessThanOrEqualToConstant:].active = YES;

6> iOS 11 新增的两个保存相册权限:

    <key>NSPhotoLibraryUsageDescription</key>
<string>App需要您的同意,才能访问相册</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>App需要您的同意,才能访问相册</string>

7> 跳转到AppStore:

-(void)goToAppStore

{

NSString *itunesurl = @"itms-apps://itunes.apple.com/cn/app/idXXXXXX?mt=8&action=write-review";

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:itunesurl]];

}
注意:把里面的XXX替换成你自己的APP ID。

 8>iOS 11返回按钮点击不灵敏:

参考博客: http://m.blog.csdn.net/wenmingzheng/article/details/78081342

iPhone X的适配:

1> 启动图:添加1125 * 2436的图片即可;

2> 安全区域上下不遮挡:

这里注意:思思一直以为所有页面都需要距离底部34的安全距离,其实没有必要,如果你的tableview是像模拟器里“设置”页面一样的话 就不用减34p ,如果tableview底部还有其他按钮的 就要减34啦!都说官方没有一定的强制要求。

参见系统设置界面:

我居然不知道参考系统的页面,还在一直的纠结要不要减去34,该打,哈哈

iOS 11适配和iPhone X的适配的更多相关文章

  1. iOS:界面适配(三)--iPhone不同机型适配 6/6plus 前

    转:http://blog.csdn.net/houseq/article/details/40051207 对于不同苹果设备,各个参数查看<iOS:机型参数.sdk.xcode各版本>. ...

  2. 关于IOS的屏幕适配(iPhone)——资源适配

    IOS的屏幕适配几乎不需要大量的代码操作,更多的时间我们只是动动鼠标选择一下就搞定.可以苹果在这方面做的还是比较人性的,解放了开发者. 首先来说说Iphone这几种屏(由于最近做的是iPhone AP ...

  3. 适配 iOS 11 & iPhone X 大全

    1.升级iOS11后造成的变化 1. 1升级后,发现某个拥有tableView的界面错乱,组间距和contentInset错乱,因为iOS11中UIViewController的automatical ...

  4. IOS 11 下适配UITableView

    9月份苹果发布了IOS11和Iphone X,这一操作系统一硬件对于开发者适配上面还是造作了不少蛋疼的地方.先来看看IOS 11,这些蛋疼的需要适配的地方: 1.UIScrollView及其子类在IO ...

  5. iOS 11 & iPhone X 适配资料集

    本文主要简单谈谈并收集一些关于 iOS 11 & iPhone X 的适配及设计指南. iPhone X 众所周知,iPhone X 屏幕与其他的 iPhone 设备均不同,苹果称 iPhon ...

  6. iOS 11更新后以及iPhone X推出后工程中遇到的问题及适配

    1.UITableView滑动时右侧的滑动条忽长忽短的乱跳以及MJRefresh上拉刷新死循环 这是因为tableView在iOS11默认使用Self-Sizing,tableView的estimat ...

  7. iPhone X 适配 ( iOS 11适配 )

    总结: 1.状态栏高度发生变化,解决方案:布局的时候这个高度不要写死,通过方法获取高度. 2.导航栏的视图层级结构发生变化而导致 UI(titleView.UIBarButtonItem) 问题. 3 ...

  8. IOS学习——iphone X的适配

    说实话,对于一个刚入门iOS两个月的新手而言,在拿到这个任务的时候整个人都是懵逼的,怎么做适配?哪些地方需要适配?该怎么做?一个个问题搞得头都大了. 首先,啥都不管,先在iPhone X上运行起来看看 ...

  9. 58 同城 iOS 客户端 iOS11 及 iPhone X 适配实践

    一.前言 前段时间 WWDC 大会上苹果推出了 iOS11 系统 和 iPhone X 新机型,相信各个 iOS 团队的开发者都已经在计划新系统和新机型的适配工作了.不得不说,新系统和新机型的发布确实 ...

随机推荐

  1. Ubuntu系统---安NVIDIA 驱动后 CUDA+cuDNN 安装

    Ubuntu系统---安NVIDIA 驱动后  CUDA+cuDNN 安装 --------------------------------------------@20190726--------- ...

  2. Python命令行创建虚拟环境

    Python命令行创建虚拟环境 安装virtualenv 启动命令行,执行命令pip install -U virtualenv 创建一个新的虚拟环境 执行命令python -m virtualenv ...

  3. JAVA遇见HTML——JSP篇:JSP内置对象(下)

    什么是session session表示客户端与服务器的一次会话 Web中的session指的是用户在浏览某个网站时,从进入网站到浏览器关闭所经过的这段时间,也就是用户浏览这个网站所花费的时间 从上述 ...

  4. Spring-HelloSpring-IOC创建对象的方式

    3.HelloSpring 思考 Hello 对象是谁创建的 ? [ hello 对象是由Spring创建的 ] Hello 对象的属性是怎么设置的 ? [hello 对象的属性是由Spring容器设 ...

  5. K3CLOUD 常用数据表

    二.K3 Cloud 开发插件<K3 Cloud 常用数据表整理>一.数据库查询常用表 按 Ctrl+C 复制代码 按 Ctrl+C 复制代码 通过表T_META_OBJECTTYPE的F ...

  6. BZOJ 4008 亚瑟王(概率DP 奥妙重重)

    题意 中文题面,就不解释了 分析 显然这道题直接求期望太麻烦,想想转化问题(这转化太神了). 定义f(i,j)f(i,j)f(i,j)表示第iii张卡总共被经过jjj次的概率,有转移方程式 f(i,j ...

  7. 使用Eclipse进行远程调试(转)

    做开发好多年了,Debug大家肯定都不陌生,绝对称得上是家常便饭了.博主虽不敢妄下断言,但是这里也猜一下,肯定有很多人都没有使用过Remote Debug(远程调试).说来惭愧,博主也是工作了3年才用 ...

  8. PHP mysqli_connect_errno() 函数

    返回上一次连接错误的错误代码: <?php $con=mysqli_connect("localhost","wrong_user","my_p ...

  9. 003转载----C#打开网页

    作者:微wx笑 来源:CSDN 原文:https://blog.csdn.net/testcs_dn/article/details/42246969 版权声明:本文为博主原创文章,转载请附上博文链接 ...

  10. 2019牛客暑期多校训练营(第六场)E 构造、原图是补图的同构图

    https://ac.nowcoder.com/acm/contest/886#question 题意  问是否存在某个n个点的无向图G是其补图H的同构图,若存在输出G的邻接矩阵以及H关于G的映射. ...