进入视图时,撰写UIBarButtonItem会稍微改变位置 [英] Compose UIBarButtonItem changes position slightly when coming into view
问题描述
在导航栏中显示带有UIBarButtonSystemItemCompose按钮的新视图时,该位置会稍微偏离并在视图进入视图后进行调整.
When presenting a new view with a UIBarButtonSystemItemCompose button in the navigation bar, the position is slightly off and adjusts after the view has come into view.
我认为这是iOS(使用8.3版)中的错误.它仅在使用UIBarButtonSystemItemCompose时发生.其他类型的按钮(系统按钮,文本按钮或自定义按钮)则不会发生这种情况.
I think this is a bug in iOS (version 8.3 used). It only happens when using the UIBarButtonSystemItemCompose. It does not happen with other types of Buttons (system, text or custom).
复制此错误所需的唯一代码是将ViewController代码与将要显示的视图一起使用:
The only code needed to replicate this bug is to use this ViewController code with the view that will come into view:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIBarButtonItem* composeBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera
target:nil
action:nil];
[self.navigationItem setRightBarButtonItem:composeBarButtonItem animated:YES];
}
@end
我已经在GitHub上创建了一个存储库,并使用最少的代码来重现该问题: https://github.com/jvdvleuten/iOSComposeBarButtonItemBug
I have created a repository on GitHub with bare minimum code to reproduce the problem: https://github.com/jvdvleuten/iOSComposeBarButtonItemBug
与此相关的外观: UIBarButtonItems模态显示UINavigationController时的位置,除了我的错误仅在使用UIBarButtonSystemItemCompose时出现.
Looks related to this: UIBarButtonItems shift position when UINavigationController is presented modally, except my bug only appears when using the UIBarButtonSystemItemCompose.
有什么想法吗?
推荐答案
我使用了谢尔盖(Sergey)的答案,但在按钮右侧保留了一个空白区域.我用一个负隔离片固定了它,现在可以很好地工作了:
I used Sergey's answer, but kept an empty space right of my button. I fixed this with a negative spacer, which now works beautifully:
UIBarButtonItem* composeBarButtonItem =
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose
target:nil
action:nil];
UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
target:nil action:nil];
negativeSpacer.width = -6;
UIBarButtonItem *dumbBarButtonItem = [UIBarButtonItem new];
self.navigationItem.rightBarButtonItems = @[dumbBarButtonItem, negativeSpacer, self.composeBarButtonItem];
这篇关于进入视图时,撰写UIBarButtonItem会稍微改变位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!