我正在尝试将 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
[self.view addSubview:alertView]
是在视图控制器或 UIWindow 内部调用后引起的。