【发布时间】:2013-11-15 12:08:05
【问题描述】:
我遇到了一个问题。工具栏在iOS7 iphone 5s真机前添加内边距。
;
但是,在模拟器和 iOS7 iphone 4s 设备上都没有出现此问题。
我的配置是这样的
任何人都可以指出什么可能是错的?提前致谢
【问题讨论】:
标签: ios iphone uitoolbar uisegmentedcontrol
我遇到了一个问题。工具栏在iOS7 iphone 5s真机前添加内边距。
;
但是,在模拟器和 iOS7 iphone 4s 设备上都没有出现此问题。
我的配置是这样的
任何人都可以指出什么可能是错的?提前致谢
【问题讨论】:
标签: ios iphone uitoolbar uisegmentedcontrol
即使我也遇到了同样的问题(但是,在模拟器和设备中都看到了)。我使用setWidth 消息来限制每个段的宽度。所以,类似:-
[segmentedControl setWidth:75.0f forSegmentAtIndex:0];
应该可以解决这个问题。不过我没有使用故事板
【讨论】:
我并不为这个修复感到自豪,但它确实为我修复了它:
// in the app delegate class
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
// in the view
- (void)fixToolbarWidth
{
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0"))
{
float adjust = -10.5f;
// self.toolbar is linked to the UIToolbar
self.toolbar.frame = CGRectMake(adjust, 0, [SizeHelper getSizeInOrientation].width-adjust, self.toolbar.frame.size.height);
// self.segmentedControl is linked to the UISegmentedControl
self.segmentedControl.frame = CGRectMake(0, 0, self.toolbar.frame.size.width+(adjust*2), self.segmentedControl.frame.size.height);
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
// fix on first load
[self fixToolbarWidth];
}
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
// resize if they rotate the device
[self fixToolbarWidth];
}
更新/更简单的版本
只要您的工具栏和分段控制器正确设置为缩放 .xib 文件中的整个宽度,您就可以在 viewDidLoad 中执行以下操作
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0"))
{
// use a different adjustment for iPad vs iPhone/touch
float adjust = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) ? -14.0f : -9.0f;
self.toolbar.frame = CGRectMake(adjust, 0, self.toolbar.frame.size.width-adjust, self.toolbar.frame.size.height);
self.segmentedControl.frame = CGRectMake(0, 0, self.segmentedControl.frame.size.width+adjust, self.segmentedControl.frame.size.height);
}
【讨论】:
我也有同样的问题。我所做的是将段控件从工具栏上移出。这对我有用。
【讨论】: