3

我遇到了一个问题。工具栏在iOS7 iphone 5s真机前添加了padding。

错误图像;

但是,该问题在模拟器或 iOS7 iphone 4s 设备上均未出现。

我的配置如下

界面配置

任何人都可以指出什么可能是错的?提前致谢

4

4 回答 4

3

即使我遇到了同样的问题(但是,在模拟器和设备中都看到了它)。我使用setWidth消息来限制每个段的宽度。所以,像: -

[segmentedControl setWidth:75.0f forSegmentAtIndex:0];

应该解决这个问题。虽然我没有使用故事板

于 2013-11-04T19:10:34.287 回答
1

我对这个修复并不感到自豪,但它确实为我修复了它:

// 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);
}
于 2013-11-05T21:47:03.570 回答
0

我也遇到同样的问题。我所做的是将段控件从工具栏上移出。这对我有用。 在此处输入图像描述

于 2014-05-20T03:26:42.840 回答
0

如果有人仍在寻找不包括固定段宽度的答案,您需要Flexible SpaceSegmented ControlUIToolbar

在此处输入图像描述

于 2015-10-16T07:54:04.880 回答