美文网首页
iOS11和Xcode9试用后部分问题汇总

iOS11和Xcode9试用后部分问题汇总

作者: 你说明哥我说哎 | 来源:发表于2017-09-19 16:18 被阅读223次
  • tableView:heightForFooterInSection: 设置无效

在iOS11之前,如下的设置没有任何问题,但最近在使用Xcode9做适配iOS 11的时候发现下面的代码无效。

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    if (section == 0) {
        return 0.001;
    }
    return 30;
}

修改的方法如下:

  • 方法一
    在viewDidLoad中添加如下代码
if (@available(iOS 11.0, *)) {
      self.tableView.estimatedRowHeight = 0;
      self.tableView.estimatedSectionHeaderHeight = 0;
      self.tableView.estimatedSectionFooterHeight = 0;
}
  • 方法二
    实现UITableViewDelegate中的tableView:viewForFooterInSection:方法
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
        return nil;
}
#endif

是的,即使是返回nil也会使高度设置生效。


  • 自定义UINavigationBar和UIToolBar坐标问题

这个问题是必然的,毕竟苹果对它们进行了修改,在这里我只说一下刚刚我遇到的问题。
此处省略一万行代码,仅做说明只用。

// UIToolbar,其中rectButton、circleButton 有一个buttonClick:方法
UIToolbar *markToolBar = [[UIToolbar alloc] initWithFrame:CGRectZero];    
UIBarButtonItem *rectItem = [[UIBarButtonItem alloc] initWithCustomView:self.rectButton];
UIBarButtonItem *circleItem = [[UIBarButtonItem alloc] initWithCustomView:self.circleButton];   

UIBarButtonItem *flexibleitem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:(UIBarButtonSystemItemFlexibleSpace) target:self action:nil];

NSArray *items = @[rectItem,flexibleitem,circleItem];
[markToolBar setItems:items animated:YES];

在这里,当button点击后我需要得到button的坐标
iOS 11 之前我是这样获得的

-(void)buttonClick:(UIButton *)sender {
CGRect viewFrame = sender.frame;
}

使用Xcode9在iOS11的模拟器上,这样的得到的坐标为(0, 0, 30, 30)。
发现问题了吧,CGPoint是(0, 0). 这就不对了。
没办法,只能这样改了,凑活着用把。

-(void)buttonClick:(UIButton *)sender {
CGRect viewFrame = [sender convertRect:sender.bounds toView:self];
}


  • 使用Xcode8.x 和 Xcode9多次编译代码出现了真机可以编译通过,但模拟器编译不通过的情况

关键词:Xcode、真机编译通过、模拟器编译失败

首先,代码是没有问题的,在之前使用的时候,无论是真机还是模拟器使用都是正常的。这就排除了某个库不支持模拟器的情况。
使用模拟器编译,提示的问题是

lexical or preprocessor issue
"xxx.h" file not found
类似这些错误提示。

经过了一次次的重启模拟器,重启Xcode,重启电脑,重启大脑,重启..........
最后得解决方案是在 --- 本地电脑清除模拟器缓存文件 --- 解决


  • UITableView和UICollectionView完美适配iOS11

关键词:UITableView、UICollectionView
在Appdelegate.m中的didFinishLaunchingWithOptions:方法中添加如下代码,就可以全局适配iOS 11中UITableView和UICollectionView了。

    if (@available(ios 11.0,*)) {
    UIScrollView.appearance.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    UITableView.appearance.estimatedRowHeight = 0;
    UITableView.appearance.estimatedSectionFooterHeight = 0;
    UITableView.appearance.estimatedSectionHeaderHeight = 0;
    }

每一次iOS更新,都是一场没有硝烟的战争。但是我喜欢这场战争,因为我也是参与者。什么?又要做适配?!好的,稍等,容我喝了这杯茶。

相关文章

网友评论

      本文标题:iOS11和Xcode9试用后部分问题汇总

      本文链接:https://www.haomeiwen.com/subject/foawsxtx.html