时间:2010-01-30 02:20:47

标签: iphone objective-c uiview

我在.xib中的UIView中的UIScrollView中有一个UIView,它包含几个按钮。如果我将那个UIView向下移动viewWillAppear内的几个像素,则这些按钮都会停止响应水龙头。

这是我用来调整UIScrollView大小并按下按钮的代码:

    // adjust the view height to accomodate the resized label
    scrollView.contentSize = CGSizeMake( 320, 367 + expectedLabelSize.height - originalLabelSize.height );

    // Adjust the location of buttons
    CGRect buttonsBounds = buttons.bounds;
    buttonsBounds.origin.y -= expectedLabelSize.height - originalLabelSize.height; //XX
    buttons.bounds = buttonsBounds;

如果我注释掉标记为XX的行,按钮工作正常,但当然是在错误的位置。

如果我尝试不同数量的像素(用硬编码值替换expectedLabelSize.height - originalLabelSize.height),我会得到有趣的结果。 10像素工作正常。 50像素使我的顶部按钮工作正常但我的底部按钮失败。 100像素,两个按钮都失败。 (-50)像素使底部按钮正常工作,但顶部失败。

知道可能导致问题的原因是什么?我是否需要通知按钮他们的父视图已移动?

2 个答案:

答案 0 :(得分:2)

问题是我本应该使用buttons.frame而不是buttons.bounds。使用框架来修复问题。

答案 1 :(得分:1)

我建议给父UIView一个背景颜色并将按钮样式设置为Rounded。这样你就可以真正看到屏幕上发生的事情。 (假设您在某个图像的顶部使用透明按钮)