UIBarButtonItem翻转过渡后自定义背景外观“跳跃" [英] UIBarButtonItem Custom Background Appearance 'Jumping' after flip transition
问题描述
出于某种原因,当我为uibarbutton项设置自定义背景图片时:
UIImage *button30 = [[UIImage imageNamed:@"nav_bar_button_orange.png"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 5)];
[[UIBarButtonItem appearance] setBackgroundImage:button30 forState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];
我的按钮是在水平翻转中跳跃"或更新其宽度(或更准确地说是在文本的两边填充).
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStylePlain handler:^(id sender) {
[self dismissViewControllerAnimated:YES completion:nil];
}];
忽略处理程序位,我正在使用BlocksKit.
您可以在这里看到它的发生情况: http://screencast.com/t/HZRBS70OT6wt >
其他信息
当我将按钮放置在情节提要中而不是代码中时,它甚至可以执行此操作.似乎只发生在水平翻转上.
原因:
显然,它与使用自定义字体有关.几乎就像一开始就没有计算宽度.
示例项目
在此示例项目中重新创建了问题.如果有人知道如何解决此问题,将不胜感激.不敢相信没有人碰上它.
我不知道此行为的原因,但是设置图像插图有助于解决此问题.
For some reason when I set a custom background image for the uibarbutton items:
UIImage *button30 = [[UIImage imageNamed:@"nav_bar_button_orange.png"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 5)];
[[UIBarButtonItem appearance] setBackgroundImage:button30 forState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];
My button is 'jumping' or updating it's width (or more accurately the padding on each side of the text) on a horizontal flip.
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStylePlain handler:^(id sender) {
[self dismissViewControllerAnimated:YES completion:nil];
}];
Ignore the handler bit, I'm using BlocksKit.
You can see it happening here: http://screencast.com/t/HZRBS70OT6wt
Additional Info
It even does this when I put the button in place in storyboard's instead of code. Only seems to happen on the horizontal flip.
Cause:
Apparently it has something to do with using a custom font. Almost like it's not calculating the width right at first.
Sample Project
Recreated the problem in this sample project. Would love if someone knew how to fix this. Can't believe nobody has run into it.
I don't know the reason of this behavior, but setting image inset helps to fix this.
这篇关于UIBarButtonItem翻转过渡后自定义背景外观“跳跃"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!