自定义self.navigationItem.titleView ,
1、必须在懒加载里设置固定的frame,不然iOS10以下,会出现抖动
2、必须设置
if (@available(iOS 11.0, )){
_titleView.translatesAutoresizingMaskIntoConstraints = NO;
_titleView.intrinsicContentSize = CGSizeMake(200SCALE_X, 45);
}
否则在iOS11以上出现自定义的点击事件不响应
-
(void)setupNav{
[self.titleView addSubview:self.titleL];
[self.titleView addSubview:self.titleIV];
self.title = @"";
self.navigationItem.titleView = self.titleView;[self.titleL mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.titleView.mas_centerX).offset(-6);
make.centerY.equalTo(self.titleView.mas_centerY);
}];
[self.titleIV mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.titleL.mas_right).offset(3);
make.centerY.equalTo(self.titleView.mas_centerY);
make.width.height.equalTo(@12);
}];@weakify(self);
[self.titleView bk_whenTapped:^{
@strongify(self);
[self chooseSeatMode];
}];
} (CCDSeatNavCustiomView )titleView{
if (!_titleView) {
_titleView = [[CCDSeatNavCustiomView alloc] initWithFrame:CGRectMake(120, 20, 180SCALE_X, 45)];
_titleView.backgroundColor = [UIColor clearColor];
_titleView.userInteractionEnabled = YES;
if (@available(iOS 11.0, )){
_titleView.translatesAutoresizingMaskIntoConstraints = NO;
_titleView.intrinsicContentSize = CGSizeMake(200SCALE_X, 45);
}
}
return _titleView;
}(UILabel )titleL{
if (!_titleL) {
_titleL = [[UILabel alloc] initWithFrame:CGRectMake(120, 20, 150SCALE_X, 45)];
_titleL.textColor = [UIColor whiteColor];
_titleL.text = CCDLocalizedString(@"addWatchedSeats", @"我关注的桌位");
_titleL.textAlignment = 1;
_titleL.userInteractionEnabled = YES;
}
return _titleL;
}(UIImageView *)titleIV{
if (!_titleIV) {
_titleIV = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.titleL.frame)+3, 20, 12, 12)];
_titleIV.image = CCDImageFromCurrentBundle(@"select_seat_arr");
_titleIV.userInteractionEnabled = YES;
}
return _titleIV;
}