iOS11中右滑手势导致返回按钮消失
2018-01-19 本文已影响182人
一只特立独行的道哥
iOS11中右滑手势与使用leftBarButtonItems添加的返回按钮并存,当右滑时,返回按钮会消失。渲染的时候发现返回按钮那一块完全被移除了。目前只在iOS11系统上发现这种情况,如果有知情的同学可以评论回复。
我的解决办法,直接上代码:
UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 44.0, 44.0)];
leftBtn.backgroundColor = [UIColor clearColor];
leftBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
[leftBtn setImage:[UIImage imageNamed:@"icon_back"] forState:UIControlStateNormal];
[leftBtn addTarget:self action:@selector(backBtnAction:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 11.0) {
//如果是iOS 11以上版本
if ([leftItem.customView isKindOfClass:[UIButton class]]) {
UIButton *leftButton = (UIButton *)leftItem.customView;
//图片向左偏移5个像素
leftButton.imageEdgeInsets = UIEdgeInsetsMake(0, -5.0, 0, 0);
}
self.navigationItem.leftBarButtonItem = leftItem;
}else{
UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
negativeSpacer.tintColor = [UIColor redColor];
negativeSpacer.width = -5.0; //偏移距离 -向左偏移, +向右偏移
self.navigationItem.leftBarButtonItems = @[negativeSpacer,leftItem];
}