开发者

iOS: self.view.bounds does not fill the whole window

I am doing some simple testing of adding CALayer to a UIView. In my main controller class of an iPhone 4 app, I implemented the viewDidLoad method as such:

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSLog(@"%s", __PRETTY_FUNCTION__);

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

    [ca se开发者_开发百科tBackgroundColor:[[UIColor blueColor] CGColor]];

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

The blue background only occupy 1/4 of the screen.

iOS: self.view.bounds does not fill the whole window

I wonder if it is because I did not take retina display into consideration? What is the best practice in this situation?


Added these debug messages:

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);

Output:

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


setContentsScale has no effect

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

However, if I use

  [ca setFrame:self.view.bounds];

it works.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜