日常问题

一、iOS11适配问题

1、导航栏问题
自定义titleView
iOS11在自定义View上实现:

@property(nonatomic, assign) CGSize intrinsicContentSize;
//iOS 11 之后必须适配重写这个属性
- (CGSize)intrinsicContentSize
{
    return CGSizeMake(200, 40);
}

初始化的时候必须给frame否则在iOS10及以下,点击事件无效
企业微信截图_ba0d8efe-1306-4875-b24c-49a26d9e2da6.png

同样添加导航栏按钮的时候,如果使用下面的代码。则必须给frame,如果没有frame在iOS11没有问题,但iOS10就会消失

UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[rightBtn addTarget:self action:@selector(refresh) forControlEvents:UIControlEventTouchUpInside];
[rightBtn setTitle:@"刷新" forState:UIControlStateNormal];
[rightBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn]; 

二、tableView问题

TableviewFooter or HeaderView高度不能使用约束动态设置,只能设置frame。如果使用了自动布局,请给出具体高度,或者强制刷新布局信息[self layoutIfNeeded],拿到frame信息。
(注意:想要拿到哪个view的frame,必须强制刷新父视图)

或者使用下面的方法动态设置tableHearderView高度( 推荐使用):

UIView *tableHearderView = [[UIView alloc] init];
tableHearderView.backgroundColor = [UIColor lwm_colorWithHexString:@"f5f5f5"];

UIView *backView = [[UIView alloc] init];
backView.backgroundColor = [UIColor lwm_colorWithHexString:@"efefef"];
[tableHearderView addSubview:backView];
[backView mas_makeConstraints:^(MASConstraintMaker *make) {
       make.left.bottom.right.top.equalTo(tableHearderView);
       make.height.mas_equalTo(40);
}];

CGFloat height = [tableHearderView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
CGRect frame = tableHearderView.bounds;
frame.size.height = height;
tableHearderView.frame = frame;
[self.tableView setTableHeaderView:tableHearderView];

不要再layoutSubviews上获取自动布局控件frame给height赋值,会无效

tableView加载完成方法

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if([indexPath row] == ((NSIndexPath*)[[tableView indexPathsForVisibleRows] lastObject]).row){
        //end of loading
        dispatch_async(dispatch_get_main_queue(),^{
            LWMLog(@"刷新完成%@",NSStringFromCGSize(self.contentSize));
 
        });
    }
}

iOS 11 tableView与顶部控件,或者导航栏之间的有大量的留白

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return nil;
}
有时候tableview的底部视图也会出现此现象对应的修改就好了
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return nil;
}

tableview刷新数据后tableview偏移问题:
你用了estimatedHeightForRowAtIndexPath里预算高度的吗?如果实际高度大于你这预算高度、可能就会发生偏移的哦

一、日常问题

1、iOS11下,控制器textField设置secureTextEntry = YES后,该控制器内所有文本不能调用第三方输入法bug处理:

if (@available(iOS 11.0, *)) {
        self.psdText.textContentType = UITextContentTypeName;
    }

2、ScrollView子控件不随容器View滚动问题:
今天在接收同事的代码出现ScrollView子控件不随容器View滚动问题:
可能导致问题:子控件设置了一个top的约束,相对于ScrollView外的控件。重新设置子控件的top约束相对于容器view

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 总结一些遇到的问题。日常工作中用到的一些方法总结,有很简单介绍,可能也有错误,如果您看到了希望可以告诉我,会不间断...
    最后还是个农阅读 5,587评论 4 7
  • 1.presentViewController和pushViewController区别:presentViewC...
    木子尚武阅读 1,917评论 0 1
  • 会导致整个页面布局产生问题,会计算导航栏的高度self.navigationController.navigati...
    BigBossZhu阅读 650评论 0 0
  • 席慕容说 愿做一棵树 为见你一面 在佛前求上五百年 简桢说 你是回不去的原乡 光阴两岸 红霞凄艳 我佛拈花一笑 了...
    公子楚澜阅读 1,144评论 0 0
  • 今天一个朋友不停地跟我抱怨她的孩子怎么怎么糟糕…我突然问了一句:如果刚才你描述的这个孩子不是你的,而是我的,你还这...
    俞燕文阅读 2,206评论 0 0