我正在做一些将 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