自定義self.navigationItem.titleView 彪置,
1悉稠、必須在懶加載里設置固定的frame艘包,不然iOS10以下,會出現(xiàn)抖動
2卦尊、必須設置
if (@available(iOS 11.0, )){
_titleView.translatesAutoresizingMaskIntoConstraints = NO;
_titleView.intrinsicContentSize = CGSizeMake(200SCALE_X, 45);
}
否則在iOS11以上出現(xiàn)自定義的點擊事件不響應
-
(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;
}