Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I remove or hide a sublayer?

-(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];
    }
}

This allows the layer to appear but I can't remove it or hide it upon clicking the same button.

like image 211
Rola Masrie Avatar asked Dec 03 '13 10:12

Rola Masrie


People also ask

How do I delete a layer in Swift?

Swift 3.0 & Swift 4.0Set the sublayers property to nil to remove all sublayers from a view.

What is Calayer in Swift?

An object that manages image-based content and allows you to perform animations on that content.


1 Answers

Replace your existing code with this one

-(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];
    }
}
like image 102
Pradhyuman sinh Avatar answered Oct 10 '22 05:10

Pradhyuman sinh