views:

154

answers:

2

I have a UIView in a UIScrollView in a UIView in a .xib that contains several buttons. If I move that UIView down by several pixels from within viewWillAppear, the buttons all stop responding to taps.

Here's the code I'm using to resize the UIScrollView and shift the buttons down:

    // 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;

If I comment out the line marked XX, the buttons work just fine, but are in the wrong place of course.

If I try various numbers of pixels (replacing expectedLabelSize.height - originalLabelSize.height with a hardcoded value), I get interesting results. 10 pixels works fine. 50 pixels causes my top button to work fine but my bottom one to fail. 100 pixels and both buttons fail. (-50) pixels causes the bottom button to work fine but the top to fail.

Any idea what might be causing the problem? Do I somehow need to inform the buttons that their parent view has moved?

+1  A: 

I suggest giving the parent UIView a background color and setting the button style to Rounded. That way you can actually see what is happening on the screen. (Assuming you are using transparent buttons on top of some image or so)

St3fan
nice suggestion, that helped me figure out what was going on. Cheers!
Mike
+1  A: 

The problem was that I should have been using buttons.frame instead of buttons.bounds. Using the frame instead fixed the problem.

Mike