iOS 8之后的布局问题

iOS 8之后的布局问题,ios,layout,ios8,Ios,Layout,Ios8,我有一个简单的视图,水平方向有3个街区。每个块是一个小图像和2个标签,块之间是一个小竖条。在资源中,它们一个接一个地放置。我使用以下代码将各个图像和标签放置在正确的位置: - (void)layoutRankingFields { // remove lines for (UIView *subview in [self subviews]) { if (subview.tag == LINE1_TAG || subview.tag == LINE2_TA

我有一个简单的视图,水平方向有3个街区。每个块是一个小图像和2个标签,块之间是一个小竖条。在资源中,它们一个接一个地放置。我使用以下代码将各个图像和标签放置在正确的位置:

- (void)layoutRankingFields
{
    // remove lines
    for (UIView *subview in [self subviews])
    {
        if (subview.tag == LINE1_TAG || subview.tag == LINE2_TAG)
        {
            [subview removeFromSuperview];
        }
    }

    // we need a separator space on all sides of the three groups
    float totalWeeks = self.imageWeeks.frame.size.width + [self widthForLabel:self.nrWeeks] + [self widthForLabel:self.labelWeeks];
    float totalHighest = self.imageHighest.frame.size.width + [self widthForLabel:self.nrHighest] + [self widthForLabel:self.labelHighest];
    float totalYear = self.imageYear.frame.size.width + [self widthForLabel:self.nrYear] + [self widthForLabel:self.labelYear];
    float widthSeparator = (self.frame.size.width - (totalWeeks + totalHighest + totalYear + 8 /*spacing between nr and label field and 2 separator lines*/)) / 6;

    // now reposition all fields
    // weeks
    float floatX = widthSeparator;
    [self repositionSubView:self.imageWeeks xpos:floatX];
    floatX = floatX + self.imageWeeks.frame.size.width;
    [self repositionSubView:self.nrWeeks xpos:floatX];
    floatX = floatX + [self widthForLabel:self.nrWeeks] + 2;
    [self repositionSubView:self.labelWeeks xpos:floatX];

    // vertical separator line
    floatX = floatX + [self widthForLabel:self.labelWeeks] + widthSeparator;
    UIView *line = [[UIView alloc] initWithFrame:(CGRectMake)(floatX, 0, 1, self.bounds.size.height)];
    line.backgroundColor = [UIColor colorWithWhite:224/255.0f alpha:1.0f];
    [line setTag:LINE1_TAG];
    [self addSubview:line];
    [line release];

    // highest
    floatX = floatX + 1 + widthSeparator;
    [self repositionSubView:self.imageHighest xpos:floatX];
    floatX = floatX + self.imageHighest.frame.size.width + 2;
    [self repositionSubView:self.nrHighest xpos:floatX];
    floatX = floatX + [self widthForLabel:self.nrHighest] + 2;
    [self repositionSubView:self.labelHighest xpos:floatX];

    // vertical separator line
    floatX = floatX + [self widthForLabel:self.labelHighest] + widthSeparator;
    line = [[UIView alloc] initWithFrame:(CGRectMake)(floatX, 0, 1, self.bounds.size.height)];
    line.backgroundColor = [UIColor colorWithWhite:224/255.0f alpha:1.0f];
    [line setTag:LINE2_TAG];
    [self addSubview:line];
    [line release];

    // year
    floatX = floatX + 1 + widthSeparator;
    [self repositionSubView:self.imageYear xpos:floatX];
    floatX = floatX + self.imageYear.frame.size.width;
    [self repositionSubView:self.nrYear xpos:floatX];
    floatX = floatX + [self widthForLabel:self.nrYear] + 2;
    [self repositionSubView:self.labelYear xpos:floatX];
}

- (void)repositionSubView:(UIView*)view xpos:(float)x
{
    CGRect frame = view.frame;
    frame.origin.x = x;
    view.frame = frame;
    view.hidden = FALSE;
    [view setNeedsLayout];
}
但是,在iOS 8上运行时,最后一个块将放置在前面的标签上。垂直杆放置正确。我添加了一些日志来查看计算的值,它们在iOS 7和iOS 8之间是相同的


有什么建议吗?

经过进一步调查,似乎在iOS 8上没有正确执行子视图。我已将此功能添加到原始问题中。更多信息:当我按Home键关闭应用程序,然后再次打开应用程序时,布局明显翻转到位。