沃梦达 / IT编程 / 移动开发 / 正文

浅谈Xcode9 和iOS11适配和特性

本篇文章主要介绍了Xcode9 和iOS11适配和特性,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

今天升级了Xcode9 刚才写了一篇 爱劈叉的齐刘海

现在说说新的东西把,有些简直不能再恶心了但有些简直不能再贴心

首先是跳转, 之前按住Command + 左键 就可以跳转了;然而今天我发现 除了这个:

说完Xcode9 再说说iOS11

1.相册权限需要增加,不然会造成闪退哟

增加info.Plist中的字段:

之前的这个字段:Privacy - Photo Library Usage Description

需要增加这个字段Privacy - Photo Library Additions Usage Description,内容和上面字段保持一致即可。

2.UITableViewStyleGrouped样式的UITableView的sectionHeader和sectionFooter有一个默认的高度,通常不需要显示header或者footer的时候,会这么写


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  return CGFLOAT_MIN;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  return CGFLOAT_MIN;
}

但是在iOS11里面你会发现段头段尾又回来辣!改了各种新增的属性比如safeArea之类的一点用都没有,最后发现必须要把estimatedSectionHeaderHeight置0才变回去

3.在iOS11中,苹果开放了NFC(Near field communication),怕也是其推广ApplePay的一种策略。
在使用近场通讯时,首先也要在info.plist配置NFCReaderUsageDescription 权限,案例步骤,如下:

iOS 11 Core NFC - any sample code?

4.如果您在Navigation上的titleView上添加searchBar,iOS11情况下可能有问题


- (void)resetSearchBar
{
  CGFloat leftButtonWidth = 35, rightButtonWidth = 75; // left padding right padding
  UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width - leftButtonWidth - rightButtonWidth, 44)];

  self.searchBar.translatesAutoresizingMaskIntoConstraints = NO;
  [container addSubview:self.searchBar];

  CGFloat offset = (rightButtonWidth - leftButtonWidth) / 2;
  // 给searchBar添加约束
  [NSLayoutConstraint activateConstraints:@[
                       [self.searchBar.topAnchor constraintEqualToAnchor:container.topAnchor], // 顶部约束
                       [self.searchBar.leftAnchor constraintEqualToAnchor:container.leftAnchor constant:-25*ScreenScaleX], // 左边距约束
                       [self.searchBar.rightAnchor constraintEqualToAnchor:container.rightAnchor constant:0], // 右边距约束
                       [self.searchBar.bottomAnchor constraintEqualToAnchor:container.bottomAnchor], // 底部约束
                       [self.searchBar.centerXAnchor constraintEqualToAnchor:container.centerXAnchor constant:-offset], // 横向中心约束
                       //                       [self.searchBar.widthAnchor constraintEqualToAnchor:container.widthAnchor constant:width] // 宽度约束
                       ]];
  self.navigationItem.titleView = container; // 顶部导航搜索
}

还有其他问题的话希望大家能在留言中提出,我们一起学习探讨~谢谢哦

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程学习网。

本文标题为:浅谈Xcode9 和iOS11适配和特性