【发布时间】:2013-04-05 11:26:34
【问题描述】:
我正在尝试将 CALayer 添加为 UIView 子类中的子层,但是当我在 init 方法中添加子层时,当我将视图添加到另一个视图或窗口时,我得到 EXC_BAD_ACCESS。
初始化方法:
- (id)initWithTitle:(NSString *)title message:(NSString *)message
{
if ((self = [super init]))
{
self.title = title;
self.message = message;
self.alertLayer = [[CALayer alloc] init];
self.layer.cornerRadius = kCORNER_RADIUS;
self.layer.shadowRadius = 3.0;
self.layer.shadowColor = [UIColor blackColor].CGColor;
self.layer.shadowOffset = CGSizeMake(15, 20);
self.layer.shadowOpacity = 1.0;
self.alertLayer.delegate = self;
self.alertLayer.masksToBounds = YES;
self.alertLayer.cornerRadius = kCORNER_RADIUS;
[self.layer addSublayer:self.alertLayer]; // This line of code seems to cause EXC_BAD_ACCESS
}
return self;
}
EXC_BAD_ACCESS 是在视图控制器或 UIWindow 中调用 [self.view addSubview:alertView] 后引起的。
【问题讨论】:
-
alertLayer属性使用什么内存管理语义?
标签: ios uiview calayer quartz-2d uiwindow