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
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 setBackgroundColor:[[UIColor blueColor] CGColor]];
[self.view.layer addSublayer:ca];
}
The blue background only occupy 1/4 of the screen.
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
setContentsScale
没有效果但是,如果我使用
它就可以了。
setContentsScale
has no effectHowever, if I use
it works.