【发布时间】:2011-08-20 11:16:11
【问题描述】:
试图理解UIView和CALayer的关系。我阅读了 Apple 文档,但没有详细描述两者之间的关系。
为什么当我添加背景图片来查看“customViewController.view”时,我得到了不需要的黑色图像。
当我将背景图像添加到图层“customViewController.view.layer”时,图像的黑色区域消失了(这是我想要的),但是背景图像被颠倒了。这是为什么呢?
如果我要添加标签/视图/按钮/等。到view,会不会因为CAlayer是UIView支持的,所以layer的背景图会挡住它们?
-
当你设置 UIView 的背景颜色时,它会自动设置关联层的背景颜色吗?
- (void)viewDidLoad { [super viewDidLoad]; customViewController = [[CustomViewController alloc] init]; customViewController.view.frame = CGRectMake(213, 300, 355, 315); customViewController.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"login_background.png"]]; // customViewController.view.layer.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"login_background.png"]].CGColor; [self.view addSubview:customViewController.view]; }
视图中的背景图片:
- (void)viewDidLoad
{
[super viewDidLoad];
customViewController = [[CustomViewController alloc] init];
customViewController.view.frame = CGRectMake(213, 300, 355, 315);
// customViewController.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"login_background.png"]];
customViewController.view.layer.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"login_background.png"]].CGColor;
[self.view addSubview:customViewController.view];
}
view.layer 中的背景图片:
【问题讨论】:
标签: iphone ios uiview uikit calayer