iOS:self.view.bounds没有填满整个窗口

我正在做一些简单的测试,将CALayer添加到UIView中.在我的iPhone 4应用程序的主控制器类中,我实现了viewDidLoad方法
- (void)viewDidLoad
{
    [super viewDidLoad];

    NSLog(@"%s",__PRETTY_FUNCTION__);

    CALayer* ca = [[CALayer alloc] init];
    [ca setBounds:self.view.bounds];

    [ca setBackgroundColor:[[UIColor blueColor] CGColor]];

    [self.view.layer addSublayer:ca];
}

蓝色背景仅占屏幕的1/4.

我想知道是不是因为我没有考虑视网膜显示在这种情况下,最佳做法是什么?

添加了以下调试消息:

NSLog(@"frame w:%f h:%f",self.view.frame.size.width,self.view.frame.size.height);
NSLog(@"bounds w:%f h:%f",self.view.bounds.size.width,self.view.bounds.size.height);

输出

frame w:320.000000 h:460.000000
bounds w:320.000000 h:460.000000

解决方法

setContentsScale无效
[ca setContentsScale:[[UIScreen mainScreen] scale]];

但是,如果我使用

[ca setFrame:self.view.bounds];

有用.

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...