简体   繁体   English

如何去除CALayer的面罩?

[英]How to remove a CALayer's mask?

Hi guys so this is my first question on SO, this has been boggling me for hours. 嗨,大家好,这是我的第一个问题,这使我困惑了几个小时。 Here is my code. 这是我的代码。

.m .m

- (IBAction)changeMask:(id)sender {
if (!mask) {

    [wallpaperImageView.layer setMask:captionTextField.layer];

    NSLog(@"%@",captionTextField.layer);
    mask = YES;
}
else {

    wallpaperImageView.layer.mask = nil;
    NSLog(@"%@",captionTextField);
    mask = NO;
}


}

Every time wallpaperImageView.layer.mask = nil; 每次wallpaperImageView.layer.mask = nil; is called, captionTextField.layer gets deallocated. 调用后, captionTextField.layer被释放。 I am using ARC in my project. 我在项目中使用ARC。 I assigned captionTextField with @property (nonatomic, strong) I used NSZombies and got *** -[CALayer retain]: message sent to deallocated instance 0x85b5e20 我为captionTextField分配了@property @property (nonatomic, strong)我使用了NSZombies并获得了*** -[CALayer retain]: message sent to deallocated instance 0x85b5e20

How do I let the CALayer not get deallocated? 我如何不让CALayer解除分配?

You did not provide enough information. 您没有提供足够的信息。 Who owns your captionTextField? 谁拥有您的captionTextField?

Post the code that shows how you create your captionTextField, and where you store it. 发布显示如何创建captionTextField及其存储位置的代码。 You need to save a strong reference to it somewhere (strong instance variable or property) or it will indeed get released as soon as nobody holds onto it. 您需要在某个地方(强实例变量或属性)保存对它的强引用,否则,只要没有人抓住它,它实际上就会被释放。

It does not make sense that setting your wallpaperImageView's layer's mask to nil is causing your captionTextField to be released, unless you create your captionTextField and don't keep a strong reference to it. 除非您创建captionTextField且不对其进行严格引用,否则将wallpaperImageViewView图层的蒙版设置为nil导致释放captionTextField是没有意义的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM