我知道这里有很多类似的问题,我检查了一个着名的问题,然后抓住了Bounds和Frame之间的区别。
现在我遇到了一些与他们有关的问题。我和他们一起玩,但它并没有像我预期的那样显示出来。
我在这里不明白的是:
#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);
}
答案 0 :(得分:1)
44来自导航栏,占据了那么高的高度
答案 1 :(得分:1)
44
幻数值实际上来自导航栏:)而状态栏的高度为20
点。
如果您希望图像覆盖整个屏幕,则需要摆脱状态栏,或者使状态栏保持半透明状态,以便在下方显示内容。
如果您未将状态栏/导航栏设置为半透明,则原点0,0
将在您现在体验的条形图下方开始。
使用
设置状态栏[[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleBlackTranslucent];
如果您有一个显示的导航栏可以使用此
进行设置theNavigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
只有这样,您的以下代码才会在整个屏幕上显示您的内容
[self.image2 setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]
这是因为将条形设置为半透明将使它们显示为叠加。