0

This function allows me to save a UIImageView called sticker containing a UIImage. I paste the layers to 0 and it works correctly. But if I insert 2 or more UIImageView called "sticker", I remove the layers only one. I need to remove the layers from each sticker that is inserted or added.

    func saveHappyFriend() {
        self.sticker?.xButton.alpha = 0
        self.sticker?.layer.borderWidth = 0
        self.sendSaveStickyProbe()
        UIGraphicsBeginImageContextWithOptions(self.managedView.workbenchView.frame.size, true, 0)
        self.managedView.workbenchView.layer.render(in: UIGraphicsGetCurrentContext()!)

        if let image = UIGraphicsGetImageFromCurrentImageContext() {
            UIGraphicsEndImageContext()
            self.router.routeToShareScene(from: self, with: image)
        } else {
            UIGraphicsEndImageContext()
        }
    }
Nilanshu Jaiswal
  • 1,583
  • 3
  • 23
  • 34
  • Can you please explain your problem clearly – Ruban4Axis Nov 19 '18 at 11:26
  • I have a view, where I can insert infinite imageView called "sticker", I need to remove the layer to all those present. while with this code I delete the layer I am at the first imageView inserted. @Ruban4Axis –  Nov 19 '18 at 11:32
  • We can not see any code that is inserting or removing any layers. To remove all subLayers from a `view` you can try `self.view.layer.sublayers?.forEach({ $0.removeFromSuperlayer()})` – Kamran Nov 19 '18 at 11:49
  • @Kamran strange thing, this way does not change anything. they always remain –  Nov 19 '18 at 11:58
  • Put breakpoint in `forEach`, see if layers are getting removed or not. As you didn't show any code so i am not sure about retain cycles. – Kamran Nov 19 '18 at 12:02

0 Answers0