Custom view can only handle the events that occur within itself ! And it is not just an "other" view, it is the parent view that contains the custom one.
So you are looking for something a bit contradictory.
Unless you mean that you do not want to reference directly the view in another view.
Then you can use notification.
First, define the name of the Notification in an extension:
extension Notification.Name {
public static let kHideCustom = Notification.Name("hideCustom")
}
Make customView subscribe to the notification, in viewDidLoad
NotificationCenter.default.addObserver(self, selector: #selector(hideMe), name: .kHideCustom, object: nil)
declare the func in customView
@objc func hideMe() {
self.isHidden = true
}
In the parent view, just post a notification instead of acting directly on the customView
@IBAction functapOnView(_ sender: UIControl) {
NotificationCenter.default.post(name: .kHideCustom, object: self)
}