tags:

views:

2556

answers:

2

I am new to iPhone programming and I am trying to understand how frame and bounds properties work. In the Interface builder I created UIView where I put UIImageView as a child. I made UIImageView bigger than parent view. and set 'clip subview' property to true for parent UIView and to false for child UIImageView.
When I change frame.origin property of the child UIImageView programmatically. but when I change 'bounds.origin' property of the parent UIView I see nothing. Probably I wrongly understand the purpose of 'bounds'.

What should I do to get the behaviour described in the iPhone Application programming guide:

You can change the bounds origin without changing the other two properties. When you do, the view displays the portion of the underlying image that you have identified. InFigure2-4 (page 56), the original bounds origin is set to(0.0,0.0). In Figure2-5, that origin is moved to (8.0,24.0).As a result,a different portion of the underlying image is displayed by the view. Because the frame rectangle did not change, however, the new content is displayed in the same location inside the parent view as before.

Thanks in advance. Andrew

A: 

First of all, make sure you have a proper reference to the image view before you try changing its bounds. Check that it is not nil.

Second, you may need to change the rectangle and then set it again in a separate statement, like this:

CGRect rect = imageView.bounds;
rect.origin = CGPointMake(whatever, whatever);
imageView.bounds = rect;

Bounds might not even be what you want. I don't know where you got that quote, but it doesn't sound right. Try using the image view's frame to position it in its superview.

jtbandes
A: 

You might want to check this out: View Programming Guide for iPhone

I had a similar problem (Moving the displayed area of a UIView)

dkk