UIImageView边界,框架 [英] UIImageView Bounds, Frame

查看:110
本文介绍了UIImageView边界,框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这里有很多类似的问题,我检查了著名的问题,然后了解了边界和框架之间的区别.

I know there are lots of similar questions here and I checked the famous one, and then grasped the difference between Bounds, and Frame.

现在我有一些与他们有关的问题.我和他们一起玩,但是没有按我预期的显示.

Now I have some problem related to them. I played around with them , but it didn't show as I expected.

我在这里不明白的是:

  • 为什么即使我将UIImageView设置在左下角,Y的框架原点也位于顶部下方44.000000? 因为界限应该是 "UIView的边界是矩形,表示为相对于其自身坐标系(0,0)的位置(x,y)和大小(宽度,高度)." (可可:框架和界限?) 我认为框架也应该从此处的左上角开始.
  • Why the frame origin of Y is 44.000000 below the top even I set the UIImageView at the left corner? 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)." (Cocoa: What's the difference between the frame and the bounds?) I thought the frame also should start at the left corner here.

#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幻数实际上来自导航栏:)而状态栏的高度为20点.

The 44 magic number value actually comes from the navigation bar :) Whereas the height of the status bar is 20 points.

如果您希望图像覆盖整个屏幕,则需要摆脱状态栏,或者使状态栏变为半透明,以便可以在下面显示内容.

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.

如果您未将状态栏/导航栏设置为半透明,则原点0,0将从您现在正在体验的栏下面开始.

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.

状态栏设置为

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

这篇关于UIImageView边界,框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆