iOS 11适配和iPhone X的适配
这两天对自己负责的项目进行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的适配的更多相关文章
- iOS:界面适配(三)--iPhone不同机型适配 6/6plus 前
转:http://blog.csdn.net/houseq/article/details/40051207 对于不同苹果设备,各个参数查看<iOS:机型参数.sdk.xcode各版本>. ...
- 关于IOS的屏幕适配(iPhone)——资源适配
IOS的屏幕适配几乎不需要大量的代码操作,更多的时间我们只是动动鼠标选择一下就搞定.可以苹果在这方面做的还是比较人性的,解放了开发者. 首先来说说Iphone这几种屏(由于最近做的是iPhone AP ...
- 适配 iOS 11 & iPhone X 大全
1.升级iOS11后造成的变化 1. 1升级后,发现某个拥有tableView的界面错乱,组间距和contentInset错乱,因为iOS11中UIViewController的automatical ...
- IOS 11 下适配UITableView
9月份苹果发布了IOS11和Iphone X,这一操作系统一硬件对于开发者适配上面还是造作了不少蛋疼的地方.先来看看IOS 11,这些蛋疼的需要适配的地方: 1.UIScrollView及其子类在IO ...
- iOS 11 & iPhone X 适配资料集
本文主要简单谈谈并收集一些关于 iOS 11 & iPhone X 的适配及设计指南. iPhone X 众所周知,iPhone X 屏幕与其他的 iPhone 设备均不同,苹果称 iPhon ...
- iOS 11更新后以及iPhone X推出后工程中遇到的问题及适配
1.UITableView滑动时右侧的滑动条忽长忽短的乱跳以及MJRefresh上拉刷新死循环 这是因为tableView在iOS11默认使用Self-Sizing,tableView的estimat ...
- iPhone X 适配 ( iOS 11适配 )
总结: 1.状态栏高度发生变化,解决方案:布局的时候这个高度不要写死,通过方法获取高度. 2.导航栏的视图层级结构发生变化而导致 UI(titleView.UIBarButtonItem) 问题. 3 ...
- IOS学习——iphone X的适配
说实话,对于一个刚入门iOS两个月的新手而言,在拿到这个任务的时候整个人都是懵逼的,怎么做适配?哪些地方需要适配?该怎么做?一个个问题搞得头都大了. 首先,啥都不管,先在iPhone X上运行起来看看 ...
- 58 同城 iOS 客户端 iOS11 及 iPhone X 适配实践
一.前言 前段时间 WWDC 大会上苹果推出了 iOS11 系统 和 iPhone X 新机型,相信各个 iOS 团队的开发者都已经在计划新系统和新机型的适配工作了.不得不说,新系统和新机型的发布确实 ...
随机推荐
- 用js刷剑指offer(二叉树的镜像)
题目描述 操作给定的二叉树,将其变换为源二叉树的镜像. 输入描述: 二叉树的镜像定义:源二叉树 8 / \ 6 10 / \ / \ 5 7 9 11 镜像二叉树 8 / \ 10 6 / \ / \ ...
- [译] 尤雨溪:Vue 3.0 计划
[译] 尤雨溪:Vue 3.0 计划 原文:Plans for the Next Iteration of Vue.js作者:Evan You 发表时间:Sep 30, 2018译者:西楼听雨 发表时 ...
- lvs+keepalived做高可用方案1
本文我们主要讲解的是LVS通过keepalived来实现负载均衡和高可用,而不是我们第三篇文章介绍的通过手动的方式来进行配置.通过脚本的方式来显示RS节点的健康检查和LVS的故障切换.此文会通过一个实 ...
- Java8-Annotations
import java.lang.annotation.ElementType; import java.lang.annotation.Repeatable; import java.lang.an ...
- csv测试类。用起来,就是那么简单。每个单元格都是以逗号分隔
package com.hyxt.wxpay.util; import java.io.File; import java.util.ArrayList; import java.util.List; ...
- 边学边体验django--表格
在模板的末尾,我们增加一个rlt记号,为表格处理结果预留位置. 表格后面还有一个{% csrf_token %}的标签.csrf全称是Cross Site Request Forgery.这是Djan ...
- Educational Codeforces Round 72 (Rated for Div. 2) A题
Problem Description: You play your favourite game yet another time. You chose the character you didn ...
- PHP mysqli_error_list() 函数
返回最近调用函数的最后一个错误代码: <?php // 假定数据库用户名:root,密码:123456,数据库:RUNOOB $con=mysqli_connect("localhos ...
- DP的优化
参考资料: 李煜东<算法竞赛进阶指南> 斜率优化 形如: \(f[i] = min\{f[j]+val(i,j)\}\)的dp,多项式\(val(i,j)\)包含\(i,j\)的乘积项 引 ...
- 【线性代数】7-1:线性变换思想(The Idea of a Linear Transformation)
title: [线性代数]7-1:线性变换思想(The Idea of a Linear Transformation) categories: Mathematic Linear Algebra k ...