What's the difference between frame and bounds of a UIImageView?
They are both CGRects
and my program behaves the sam开发者_开发知识库e when I switch one for the other.
See UIView for documentation.
The frame property specifies the origin and size of a view in superview coordinates. The origin of the coordinate system for all views is in the upper-left corner.
The bounds property specifies the origin in the view’s coordinates and its size (the view’s content may be larger than the bounds size).
Frame and bounds are similar but frame is in reference to another object (the superview) while bounds references itself.
This question gives lots of great info. You should definitely read it.
One thing I will point out specifically from the other answer is your program will behave the same sometimes. For example, until you rotate the orientation. From the answer by tristan
Running this code:
- (void)viewDidLoad {
[super viewDidLoad];
UIWindow *w = [[UIApplication sharedApplication] keyWindow];
UIView *v = [w.subviews objectAtIndex:0];
NSLog(@"%@", NSStringFromCGRect(v.frame));
NSLog(@"%@", NSStringFromCGRect(v.bounds));
}
The output of this code is:
case device orientation is Portrait
{{0, 0}, {768, 1024}} <- frame
{{0, 0}, {768, 1024}} <- bounds
case device orientation is Landscape
{{0, 0}, {768, 1024}} <- frame
{{0, 0}, {1024, 768}} <- bounds
So yes your program will usually behave the same but not in all cases.
please go through this link.Hope this will help you.
- http://www.slideshare.net/profmido/05-views
精彩评论