UIView:右框架 - UIScrollView中的错误位置

时间:2014-03-26 09:38:06

标签: ios objective-c uiview uiscrollview

我在向UIView添加一些UIScrollView时遇到了一个奇怪的问题。 我正确地计算了View的框架,然后我将视图添加到scrollview。

第一个位置很好,第二个覆盖第一个。

我已经记录了视图的框架,但似乎没问题

查看姓名:成员  查看框架:{{0,0},{768,258}}  新框架:{{0,159},{768,258}}

查看姓名:我的评论  查看框架:{{0,0},{768,50}}  新框架:{{0,420},{768,50}}

我该如何解决?

NSInteger numberOfSections = [self.collapserSections count];

for (int index = 0; index < numberOfSections; index++)
{
    CustomCollapser *collapser = [self.collapserSections objectAtIndex:index];
    collapser.collapserIdentifier = index;
    UIView *controllerView = collapser.configuration.linkedController.view;

    if (collapser.configuration.willRemoveHeader)
    {
        totalHeight = totalHeight + controllerView.frame.size.height;
    }
    else
    {
        if(collapser.collapsed)
        {
            totalHeight = totalHeight + 50;
        }
        else
        {
            totalHeight = totalHeight + collapser.view.frame.size.height;
        }
    }

    switch (index)
    {
        case 0:
        {
            startY = 0;
        }

        break;

        default:
        {
            startY = startY + collapser.configuration.spaceFromThePreviousCollapser;
        }

        break;
    }

    if(collapser.collapsed)
    {
        [collapser.view setFrame:CGRectMake(0,
                                            startY,
                                            collapser.view.frame.size.width,
                                            50)];
    }
    else
    {
        [collapser.view setFrame:CGRectMake(0,
                                            startY,
                                            collapser.view.frame.size.width,
                                            collapser.view.frame.size.height)];
    }

    if(collapser.configuration.willRemoveHeader)
    {
        startY = startY + controllerView.frame.size.height - 50;
    }
    else
    {
        startY = startY + collapser.view.frame.size.height;
    }

    [self addSubview:collapser.view];
}

这就是我将视图加载到我的scrollview

的方法

谢谢

0 个答案:

没有答案