简体   繁体   English

UIImageView Bounds,Frame

[英]UIImageView Bounds, Frame

I know there are lots of similar questions here and I checked the famous one, and then grasped the difference between Bounds, and Frame. 我知道这里有很多类似的问题,我检查了一个着名的问题,然后掌握了Bounds和Frame之间的区别。

Now I have some problem related to them. 现在我有一些与他们有关的问题。 I played around with them , but it didn't show as I expected. 我和他们一起玩,但它并没有像我预期的那样显示出来。

What I don't understand here is: 这里我不明白的是:

  • Why the frame origin of Y is 44.000000 below the top even I set the UIImageView at the left corner? 为什么Y的帧起点低于顶部44.000000,即使我在左下角设置了UIImageView? Because bounds should be "The bounds of an UIView is the rectangle, expressed as a location (x,y) and size (width,height) relative to its own coordinate system (0,0)." 因为边界应该是“UIView的边界是矩形,表示为相对于其自己的坐标系(0,0)的位置(x,y)和大小(宽度,高度)。” ( Cocoa: What's the difference between the frame and the bounds? ) I thought the frame also should start at the left corner here. Cocoa:框架和边界之间有什么区别? )我认为框架也应该从这里的左角开始。

在此输入图像描述

#import "ViewController.h"

@interface ViewController ()

//@property (weak, nonatomic) IBOutlet UIImageView *image;
@property (weak, nonatomic) IBOutlet UIImageView *image2;

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.


//UIImage *imageView = [UIImage imageNamed:@"stanford"];

//    self.image.alpha = 1;
//    self.image.contentMode = 1;
//    self.image.image = imageView;
//    [self.image setAlpha:0.1];
//    [self.image setContentMode:UIViewContentModeCenter];
//    [self.image setImage:imageView];



    NSURL *url = [[NSURL alloc] initWithString:@"http://upload.wikimedia.org/wikipedia/commons/thumb/e/ed/Pitbull_2%2C_2012.jpg/472px-Pitbull_2%2C_2012.jpg"];
    NSData *data = [NSData dataWithContentsOfURL:url];
    UIImage *imageData = [UIImage imageWithData:data];

    [self.image2 setBounds:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    [self.image2 setImage:imageData];

    NSLog(@"frame.orign.x:%f,frame.origin.y:%f",self.image2.frame.origin.x,self.image2.frame.origin.y);







}

44来自导航栏,占据了很高的高度

The 44 magic number value actually comes from the navigation bar :) Whereas the height of the status bar is 20 points. 44幻数值实际上来自导航栏:)而状态栏的高度是20点。

If you want your image to cover the entire screen then you will need to either get rid of your status bar, or make your status bar translucent so that content can be displayed underneath. 如果您希望图像覆盖整个屏幕,则需要摆脱状态栏,或者使状态栏保持半透明状态,以便可以在下方显示内容。

If you don't set your status bar/navigation bar to translucent, then the point of origin 0,0 would start just underneath the bars as you are experiencing now. 如果您没有将状态栏/导航栏设置为半透明,则原点0,0将在您现在遇到的条形图下方开始。

status bar is set using 使用状态栏设置

[[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleBlackTranslucent];

The navigation bar, if you have one displayed can be set using this 如果您有一个显示的导航栏可以使用此设置

theNavigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;

Only then will your following code display your content across the full screen 只有这样,您的以下代码才会在整个屏幕上显示您的内容

[self.image2 setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]

This is because setting the bars to translucent will have have them displayed as overlays instead. 这是因为将条形设置为半透明将使它们显示为叠加。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM