Skip to content

Instantly share code, notes, and snippets.

@siberian1967
Forked from maxcampolo/UIView+PassThrough.swift
Last active January 4, 2017 21:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save siberian1967/ab1e15f46b5ed30d0e3060079f090ae8 to your computer and use it in GitHub Desktop.
Save siberian1967/ab1e15f46b5ed30d0e3060079f090ae8 to your computer and use it in GitHub Desktop.
UIView subclass that is transparent to all touch events besides those on eligible child views.
import UIKit
/**
UIView subclass that is transparent to all touch events besides those on eligible child views.
*/
class TKPassThroughView: UIView {
// MARK - Touch Handling
/**
Override this point and determine if any of the subviews of our transparent view are the ones being tapped. If that is the case, handle those touches otherwise pass the touch through.
*/
override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
for subview in subviews as [UIView] {
if !subview.isHidden && subview.alpha > 0 && subview.isUserInteractionEnabled && subview.point(inside: convert(point, to: subview), with: event) {
return true
}
}
return false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment