Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between frame and bounds of a UIImageView?

They are both CGRects and my program behaves the same when I switch one for the other.

like image 225
George Avatar asked Jul 13 '10 10:07

George


People also ask

What is the difference between frame and bounds?

Frame refers to the coordinate system of the view's container (parent view). Bounds refer to the own coordinate system of the view.

What's a difference between frame and bounds Swift?

TLDR: Bounds refers to the views own coordinate system while Frame refers to the views parent coordinate system.

What is frame and bound in IOS?

Short description. frame = a view's location and size using the parent view's coordinate system ( important for placing the view in the parent) bounds = a view's location and size using its own coordinate system (important for placing the view's content or subviews within itself)

What is frame in UIView?

Frame A view's frame ( CGRect ) is the position of its rectangle in the superview 's coordinate system. By default it starts at the top left. Bounds A view's bounds ( CGRect ) expresses a view rectangle in its own coordinate system.


3 Answers

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).

like image 117
willcodejavaforfood Avatar answered Nov 08 '22 13:11

willcodejavaforfood


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.

like image 38
Joshua Dance Avatar answered Nov 08 '22 13:11

Joshua Dance


please go through this link.Hope this will help you.

  1. http://www.slideshare.net/profmido/05-views
like image 33
Akshay Avatar answered Nov 08 '22 13:11

Akshay