如何处理iOS 11导航BarButtonItems错误?

如何处理iOS 11导航BarButtonItems错误?,第1张

概述我在iOS 11中发现了一个UINavigationBar错误.使用self.navigationItem.rightBarButtonItems = @ [fixSpaceItem,item]在viewDidLoad中快速设置导航项按钮.然后使用手势回d,但我没有回d,当d出回来时,我松开手指并让视图控制器取消d回,然后右侧导航按钮项目消失.左项按钮具有相同的问题.要重现此错误,您必须添加fix 我在iOS 11中发现了一个UINavigationbar错误.使用self.navigationItem.rightbarbuttonItems = @ [fixSpaceItem,item]在vIEwDIDLoad中快速设置导航项按钮.然后使用手势回d,但我没有回d,当d出回来时,我松开手指并让视图控制器取消d回,然后右侧导航按钮项目消失.左项按钮具有相同的问题.要重现此错误,您必须添加fixSpaceItem,如[[UIbarbuttonItem alloc] initWithbarbuttonSystemItem:UIbarbuttonSystemItemFixedspace target:nil action:nil].而真正的设备,但不是模拟器可以重现错误.
这是我的主要代码:
- (voID)vIEwDIDLoad {    [super vIEwDIDLoad];    self.navigationController.interactivePopGestureRecognizer.enabled = YES;    self.navigationController.interactivePopGestureRecognizer.delegate = self;    self.navigationItem.rightbarbuttonItems = @[[self negativeSpacerWithWIDth:5],[self rightbutton]];    self.navigationItem.leftbarbuttonItems = @[[self negativeSpacerWithWIDth:5],[self leftbutton]];}- (UIbarbuttonItem *)leftbutton {    UIbutton *button = [[UIbutton alloc] initWithFrame:CGRectMake(0,35,35)];    [button setimage:[UIImage imagenamed:@"icon_app_back_normal"] forState:UIControlStatenormal];    [button addTarget:self action:@selector(back) forControlEvents:UIControlEventtouchUpInsIDe];    UIbarbuttonItem *item = [[UIbarbuttonItem alloc] initWithCustomVIEw:button];    return item;}- (UIbarbuttonItem *)rightbutton {    UIbutton *button = [[UIbutton alloc] initWithFrame:CGRectMake(0,35)];    [button setimage:[UIImage imagenamed:@"setting"] forState:UIControlStatenormal];    UIbarbuttonItem *item = [[UIbarbuttonItem alloc] initWithCustomVIEw:button];    return item;}- (UIbarbuttonItem *)negativeSpacerWithWIDth:(CGfloat)wIDth {    UIbarbuttonItem *spacer = [[UIbarbuttonItem alloc] initWithbarbuttonSystemItem:UIbarbuttonSystemItemFixedspace target:nil action:nil];    [spacer setWIDth:wIDth];    return spacer;}
解决方法 将Fixedspace barbuttonItem添加到barbuttonItem数组时,这似乎是一个错误.如果要将偏移设置为导航项,可能必须使用其他方式,例如更改按钮的imageEdgeInsets.
- (voID)vIEwDIDLoad {    [super vIEwDIDLoad];    // Do not set Fixed Space type button item.    self.navigationItem.leftbarbuttonItem = [self leftbutton];    self.navigationItem.rightbarbuttonItem = [self rightbutton];    // It work too    //self.navigationItem.leftbarbuttonItems = @[[self leftbutton],[self leftbutton]];    //self.navigationItem.rightbarbuttonItems = @[[self rightbutton],[self rightbutton]];    self.navigationController.interactivePopGestureRecognizer.enabled = YES;    self.navigationController.interactivePopGestureRecognizer.delegate = self;}- (UIbarbuttonItem *)leftbutton{    UIbutton *button = [[UIbutton alloc] initWithFrame:CGRectMake(0,35)];    //...    // to add offset you want    button.imageEdgeInsets = UIEdgeInsetsMake(0,-15,15);    UIbarbuttonItem *item = [[UIbarbuttonItem alloc] initWithCustomVIEw:button];    return item;}- (UIbarbuttonItem *)rightbutton{    UIbutton *button = [[UIbutton alloc] initWithFrame:CGRectMake(0,15,-15);    UIbarbuttonItem *item = [[UIbarbuttonItem alloc] initWithCustomVIEw:button];    return item;}
总结

以上是内存溢出为你收集整理的如何处理iOS 11导航BarButtonItems错误?全部内容,希望文章能够帮你解决如何处理iOS 11导航BarButtonItems错误?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1100057.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存