gpt4 book ai didi

objective-c - 如何删除或隐藏子图层?

转载 作者:太空狗 更新时间:2023-10-30 03:35:20 25 4
gpt4 key购买 nike

-(IBAction)displayinfo:(id)sender
{
sublayer = [CALayer layer];

if (appear == NO)
{
appear = YES;
sublayer.contents=(id)[UIImage imageNamed:@"infoPalette.png"].CGImage;
sublayer.frame= CGRectMake(300,200,350,250);
[self.view.layer addSublayer:sublayer];
}
else
{
[sublayer removeFromSuperlayer];
}
}

这允许图层出现,但我无法在单击同一按钮时将其删除或隐藏。

最佳答案

用这个替换你现有的代码

-(IBAction)displayinfo:(id)sender
{

if ( appear == NO)
{
sublayer = [CALayer layer];
appear = YES;
sublayer.contents=(id)[UIImage imageNamed:@"infoPalette.png"].CGImage;
sublayer.frame= CGRectMake(300,200,350,250);
[self.view.layer addSublayer:sublayer];
}
else
{
[sublayer removeFromSuperlayer];
}
}

关于objective-c - 如何删除或隐藏子图层?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20349132/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com