-
Notifications
You must be signed in to change notification settings - Fork 44
/
PresentationContainerView.swift
34 lines (27 loc) · 1.31 KB
/
PresentationContainerView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import UIKit
public struct PassthroughOptions: OptionSet {
public let rawValue: Int
public init(rawValue: Int) {
self.rawValue = rawValue
}
public static let collapsed = PassthroughOptions(rawValue: 1 << 0)
public static let partiallyExpanded = PassthroughOptions(rawValue: 1 << 1)
public static let fullyExpanded = PassthroughOptions(rawValue: 1 << 2)
public static let all: PassthroughOptions = [.collapsed, .partiallyExpanded, .fullyExpanded]
}
protocol PresentationContainerViewDelegate: class {
func view(_ view: PresentationContainerView, shouldPassthroughTouchAt point: CGPoint) -> Bool
func view(_ view: PresentationContainerView, forTouchAt point: CGPoint) -> UIView?
}
class PresentationContainerView: UIView {
weak var touchDelegate: PresentationContainerViewDelegate?
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
guard let touchDelegate = touchDelegate,
touchDelegate.view(self, shouldPassthroughTouchAt: point),
let viewForTouch = touchDelegate.view(self, forTouchAt: point) else {
return super.hitTest(point, with: event)
}
let pointInView = viewForTouch.convert(point, from: self)
return viewForTouch.hitTest(pointInView, with: event)
}
}