Search code examples
swiftuiviewcustom-viewshowcaseview

how to close a custom class like BubbleShowcase : UIView?


i have a class

public class BubbleShowCase: UIView {

   public func dismiss() {
        animateDisappearance()
    }
}

how can i call that dismiss function on my View Controller ? i want to dismiss that custom view on custom tap


Solution

  • whatever view you have BubbleShowCase what you need to dismiss is to remove it from its superView like

    public class BubbleShowCase: UIView {
    
        public func dismiss() {
            self.removeFromSuperview()
         }
     }
    

    and if you want to animate it you can do that as well

    public class BubbleShowCase: UIView {
      
        public func dismiss() {
            UIView.animate(withDuration: 0.5, delay: duration, animations: {
            self.alpha = 0
        }) { (completed) in
            guard completed else { return }
            self.removeFromSuperview()
        }
    
      }
    }