重写navigationBar返回按钮,打包安装 pushViewcontroller崩溃问题
2017-11-09 15:58
127 查看
重写navigationBar的返回按钮后,在iOS11崩溃,11以下没有问题。
这里的重写主要是 写了返回按钮文本的偏移量,大体上的代码是这样:
[[UIBarButtonItem
appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(-100,
0) forBarMetrics:UIBarMetricsDefault];
总之 上面就是调用了setBackButtonTitlePositionAdjustment:forBarMetrics:来改变返回按钮文本的偏移量。在iOS11以前是没有问题的,但是iOS11现在是有问题的,不知到这是不是系统的bug。目前来说
苹果不修复,那就只能我们来做。
现在需要做的就是,在iOS11下,不要这么写
我首先想到的是 判断系统版本,iOS11及以上版本,用另外的方法替换。
例如if(@available(iOS 11, *)) {
[[UIBarButtonItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor clearColor]} forState:UIControlStateNormal]; [[UIBarButtonItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor clearColor]} forState:UIControlStateHighlighted];
} else {
//去掉返回按钮文字
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(-100, 0) forBarMetrics:UIBarMetricsDefault];
}
这样就规避掉iOS11调用设置偏移量的方法了。你可以试试 iOS版本全用
这里多提两句,判断系统版本可以使用多种方法,
上面那个方法是swift的判断方法,oc也有很多方法判断,例如://判断系统版本方案
//一
if (NSFoundationVersionNumber >= NSFoundationVersionNumber10_11) {
//
}
//二
NSString *systemVersion = [UIDevice currentDevice].systemVersion;
NSComparisonResult comparisonResult = [systemVersion compare:@"11.0.0" options:NSNumericSearch];
if (comparisonResult == NSOrderedAscending) {
// < iOS 11.0.0
} else if (comparisonResult == NSOrderedSame) {
// = iOS 10.0.1
} else if (comparisonResult == NSOrderedDescending) {
// > iOS 10.0.1
}
//或者
if (comparisonResult != NSOrderedAscending) {
// >= iOS 11.0.0
} else {
// < iOS 11.0.0
}
//三
double systemVersion = [UIDevice currentDevice].systemVersion.doubleValue;
if (systemVersion >= 11.0) {
// >= iOS 10.0
} else {
// < iOS 10.0
}
这里的重写主要是 写了返回按钮文本的偏移量,大体上的代码是这样:
[[UIBarButtonItem
appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(-100,
0) forBarMetrics:UIBarMetricsDefault];
总之 上面就是调用了setBackButtonTitlePositionAdjustment:forBarMetrics:来改变返回按钮文本的偏移量。在iOS11以前是没有问题的,但是iOS11现在是有问题的,不知到这是不是系统的bug。目前来说
苹果不修复,那就只能我们来做。
现在需要做的就是,在iOS11下,不要这么写
我首先想到的是 判断系统版本,iOS11及以上版本,用另外的方法替换。
例如if(@available(iOS 11, *)) {
[[UIBarButtonItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor clearColor]} forState:UIControlStateNormal]; [[UIBarButtonItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor clearColor]} forState:UIControlStateHighlighted];
} else {
//去掉返回按钮文字
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(-100, 0) forBarMetrics:UIBarMetricsDefault];
}
这样就规避掉iOS11调用设置偏移量的方法了。你可以试试 iOS版本全用
[[UIBarButtonItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor clearColor]} forState:UIControlStateNormal]; [[UIBarButtonItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor clearColor]} forState:UIControlStateHighlighted];行不行,我没有试。
这里多提两句,判断系统版本可以使用多种方法,
上面那个方法是swift的判断方法,oc也有很多方法判断,例如://判断系统版本方案
//一
if (NSFoundationVersionNumber >= NSFoundationVersionNumber10_11) {
//
}
//二
NSString *systemVersion = [UIDevice currentDevice].systemVersion;
NSComparisonResult comparisonResult = [systemVersion compare:@"11.0.0" options:NSNumericSearch];
if (comparisonResult == NSOrderedAscending) {
// < iOS 11.0.0
} else if (comparisonResult == NSOrderedSame) {
// = iOS 10.0.1
} else if (comparisonResult == NSOrderedDescending) {
// > iOS 10.0.1
}
//或者
if (comparisonResult != NSOrderedAscending) {
// >= iOS 11.0.0
} else {
// < iOS 11.0.0
}
//三
double systemVersion = [UIDevice currentDevice].systemVersion.doubleValue;
if (systemVersion >= 11.0) {
// >= iOS 10.0
} else {
// < iOS 10.0
}
相关文章推荐
- UINavigationControll采用pushViewController后如何去掉左边的返回按钮
- 不通过push,给viewcontroller自定义UINavigationBar,并加上返回按钮
- [绍棠_Swift] Swift3.0中 通过viewController push跳转到TabbarController 隐藏后退按钮问题
- UINavigationControll采用pushViewController后如何去掉左边的返回按钮
- navigationController pushViewController 多次跳转后怎么返回
- 浅论ViewController的加载 -- 解决 viewDidLoad 被提前加载的问题(pushViewController 前执行)
- IOS7以上pushViewController界面卡顿问题
- ViewController deallocted 而造成崩溃的问题
- 导航控制器在pushViewController时的动画卡顿问题
- 解决pushViewController无法进行传值的问题
- tableView滑动出现删除按钮,不点击就返回崩溃
- Push/Pop ViewController 时右上角会有奇怪黑影冒出的问题
- 实现BaseViewcontroller的滑动返回按钮效果
- UINavigationController在viewWillAppear函数中pushViewController时的问题和解决
- 在Fragment中重写返回键以及WebView加载重定向页面返回问题
- pushViewController后获得返回事件
- ViewController.view中按钮的title及颜色问题
- webview ZoomButtonsController 调用崩溃问题android.widget.ZoomButtonsController
- navigationController pushViewController 多次跳转后返回
- pushViewController的残影问题