7

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

1 回答 1

8

setContentsScale没有效果

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

但是,如果我使用

  [ca setFrame:self.view.bounds];

有用。

于 2011-05-23T11:35:31.377 回答