tags:

views:

478

answers:

2

Hi,

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.

+1  A: 

I believe what you want is

[view setNeedsDisplay];

or

[view setNeedsDisplayInRect:(CGRect)myRect];
Ian Henry
Thank a lot. I will try this one and I will you know if this fix my problem. Thanks again. =)
sasayins
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
+1  A: 

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
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?
sasayins
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
Thanks. But its weird the whole view disappeared. I did exactly what you suggested in your answers but the whole view was disappeared.
sasayins
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
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
sasayins
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.
sasayins
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