我试图将图像水平居中放置在屏幕的最底部(无论是模拟器,还是 iPhone4、iPhone5 等)。基本上我只需要将它的 y 设置为 screen_height - image_height。
UIImage *img = [UIImage imageNamed:@"my-image.png"];
UIImageView *imgView = [[UIImageView alloc]initWithImage:img];
imgView.frame = CGRectMake(0, 0, img.size.width / 2, img.size.height / 2);
CGRect screenBounds = [[UIScreen mainScreen] bounds];
CGFloat screenScale = [[UIScreen mainScreen] scale];
CGSize screenSize = CGSizeMake(screenBounds.size.width * screenScale, screenBounds.size.height * screenScale);
CGRect frame = imgView.frame;
frame.origin.x = 0;
frame.origin.y = screenSize.height - img.size.height;
imgView.frame = frame;
[self.view addSubview:imgView];
我究竟做错了什么?0,0 是屏幕的左上角,所以我不明白为什么 screen_height - image_height 在这里是错误的......?