1

I have a UIImageView called zigZag. All I want to do is set a layer mask on it so that it is not visible at all.

I then want to animate the layer mask later so that the UIImageView becomes visible again.

I have been working on this for 4 hours now and can't seem to figure out what the heck I'm doing wrong.

// Setup the mask layer
// Make it the same size as our zigZag image
// so that the entire image is covered and not visible

let maskLayer = CALayer()      
maskLayer.frame = self.zigZag!.frame

self.zigZag!.layer.mask = maskLayer

This works, and the zigZag UIImageView is not visible on screen, but here's the thing. I can literally pass in any value I want to maskLayer.frame and it will still be hidden.

This leads me to believe that I am doing something fundamentally wrong when thinking about creating my mask layers. There is a lot more to this problem I am trying to achieve, but I figured the first step was figuring out how to properly set a mask layer to hide an entire UIImageView to make it appear as if it is not even on screen.

Thanks for the help I greatly appreciate it.

user3344977
  • 3,584
  • 4
  • 32
  • 88
  • Remember that `Fully or partially opaque pixels allow the underlying content to show through but fully transparent pixels block that content.` – onmyway133 Mar 28 '17 at 08:14

1 Answers1

0

is there any other views behind the imageView? if not, try this

    let maskLayer = CALayer()
    maskLayer.frame = CGRectMake(0, 0, 10, 10)
    maskLayer.backgroundColor = UIColor.whiteColor().CGColor
    self.zigzagImageView.image = img;
    self.zigzagImageView.layer.addSublayer(maskLayer)
Shebin Koshy
  • 1,182
  • 8
  • 22