0

I have a subview in a UIScrollView and it seems the view is distorted when every time I zoom out or in the content view. As described here by Brad Larson that I must set some transform values and redraw the content view. Now my problem is how can I redraw my content view. The content view of the UIScrollView is a UIView with UIButtons subviews. Should I remove that UIView from my UIScrollView then add again?

Thanks.

Community
  • 1
  • 1
domlao
  • 15,663
  • 34
  • 95
  • 134

2 Answers2

2

What you'll want to do is manually resize and relayout each of your buttons to account for the new scale factor that the UIScrollView has presented you in the -scrollViewDidEndZooming:withView:atScale: delegate method.

This can be done by looping through your UIButtons and adjusting their frames with their new calculated positions and sizes. The UIButtons will redraw themselves sharply at the new scale factor.

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
  • I see, so I have to remove the main UIView or the content view with UIButtons, then alloc the UIView again and add each UIButton in the UIView then set each UIButton its frame using CGRectMake? – domlao Dec 07 '09 at 05:15
  • 1
    No, there is no need to remove any views. Simply set the frames of the UIButtons to their new sizes and positions, and set the overall view's size to match. Everything will redraw as needed. – Brad Larson Dec 07 '09 at 13:34
  • Thanks. But its weird the whole view disappeared. I did exactly what you suggested in your answers but the whole view was disappeared. – domlao Dec 07 '09 at 22:01
  • How large did the main view get? If it exceeds 2048 pixels wide or high, that's more than the texture size supported by the GPU and your view won't display. – Brad Larson Dec 08 '09 at 02:21
  • Not that too large. I think I just missed something in my redraw implementation. I don't know where, I think I will just play around it. Thanks – domlao Dec 08 '09 at 03:08
  • Hi, I just made it redraw sharply. But my problem is every time I zoom in or out, the size of the content view is the not the same as the actual size of the my current view. What I mean is if I made a pinch gesture the size of the content view will automatically change to small. – domlao Dec 08 '09 at 07:22
  • I'm not sure that I understand what you are saying. On redraw of your buttons, you will also manually resize the view that contains those buttons so that they are all within it. After that is done, you will want to set the contentSize property of your scroll view to match. – Brad Larson Dec 09 '09 at 21:38
1

I believe what you want is

[view setNeedsDisplay];

or

[view setNeedsDisplayInRect:(CGRect)myRect];
Ian Henry
  • 22,255
  • 4
  • 50
  • 61
  • Thank a lot. I will try this one and I will you know if this fix my problem. Thanks again. =) – domlao Dec 06 '09 at 23:59
  • 2
    Actually, this won't help, because the UIButtons will need to have their frames adjusted to reflect the changed scale factor. Simply refreshing them will do nothing. – Brad Larson Dec 07 '09 at 03:03