这两天对自己负责的项目进行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. SpringBoot LoggerFactory is not a Logback LoggerContext but Logback is on the classpath

    SpringBoot 在启动项目的时候一起错误: SLF4J: Class path contains multiple SLF4J bindings.SLF4J: Found binding in ...

  2. APP微信登录 服务器处理代码

    采用框架THINKPHP5 需要客户端传的参数有  udid openid nickname avatar_path /* * @param 第三方微信登录 * @param openid udid ...

  3. 谷歌,火狐提示来自"http://xxx.com/file"的资源已被阻止,因为 MIME 类型("text/plain")不匹配(X-Content-Type-Options: nosniff),如何解决?

    在使用ueditor编辑的过程中无法上传图片,谷歌火狐浏览器提示Cross-Origin Read Blocking (CORB) blocked cross-origin response http ...

  4. python 打印 str 字符串的实际内容 repr(str)

    python 打印 str 字符串的实际内容 repr(str) s = 'aa' print(repr(s))

  5. Linux系统chmod 777 误操作目录权限 - 恢复方法

    小白操作Linux,手抖导致误修改了系统文件和目录权限,导致系统宕机的修复. -R / -R / test 有的是真不懂,执行了上面的第一条命令,有的是懂,但是操作太快或者粗心大意,或者有乱敲空格的恶 ...

  6. Java8-Lock-No.02

    import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util ...

  7. C# 动态加载程序集

    定义动态程序集 namespace DynamicAssembly { public class CodeDriver : MarshalByRefObject { private string pr ...

  8. linux 信号量

    https://www.jianshu.com/p/6e72ff770244 无名信号量 #include <time.h> #include <stdio.h> #inclu ...

  9. python的logging日志模块(二)

    晚上比较懒,直接搬砖了. 1.简单的将日志打印到屏幕   import logging logging.debug('This is debug message') logging.info('Thi ...

  10. js字符串字母大小写转换

    toLocaleUpperCase 方法 返回一个字符串,其中所有的字母字符都被转换为大写,同时适应宿主环境的当前区域设置. stringVar.tolocaleUpperCase( )必选的 str ...