@@ -15,11 +15,11 @@ import UIKit
15
15
and a configurable tap handler. Message views do not need to inherit from `BaseVew`.
16
16
*/
17
17
open class BaseView : UIView , BackgroundViewable , MarginAdjustable {
18
-
18
+
19
19
/*
20
20
MARK: - IB outlets
21
21
*/
22
-
22
+
23
23
/**
24
24
Fulfills the `BackgroundViewable` protocol and is the target for
25
25
the optional `tapHandler` block. Defaults to `self`.
@@ -32,24 +32,24 @@ open class BaseView: UIView, BackgroundViewable, MarginAdjustable {
32
32
installTapRecognizer ( )
33
33
}
34
34
}
35
-
35
+
36
36
// The `contentView` property was removed because it no longer had any functionality
37
37
// in the framework. This is a minor backwards incompatible change. If you've copied
38
38
// one of the included nib files from a previous release, you may get a key-value
39
- // coding runtime error related to contentView, in which case you can subclass the
39
+ // coding runtime error related to contentView, in which case you can subclass the
40
40
// view and add a `contentView` property or you can remove the outlet connection in
41
41
// Interface Builder.
42
42
// @IBOutlet public var contentView: UIView!
43
43
44
44
/*
45
45
MARK: - Initialization
46
46
*/
47
-
47
+
48
48
public required init ? ( coder aDecoder: NSCoder ) {
49
49
super. init ( coder: aDecoder)
50
50
backgroundView = self
51
51
}
52
-
52
+
53
53
public override init ( frame: CGRect ) {
54
54
super. init ( frame: frame)
55
55
backgroundView = self
@@ -83,16 +83,17 @@ open class BaseView: UIView, BackgroundViewable, MarginAdjustable {
83
83
let bottom = NSLayoutConstraint ( item: backgroundView, attribute: . bottom, relatedBy: . equal, toItem: self , attribute: . bottomMargin, multiplier: 1.0 , constant: 0 )
84
84
let right = NSLayoutConstraint ( item: backgroundView, attribute: . right, relatedBy: . equal, toItem: self , attribute: . rightMargin, multiplier: 1.0 , constant: 0 )
85
85
addConstraints ( [ top, left, bottom, right] )
86
+ installTapRecognizer ( )
86
87
}
87
88
88
89
/**
89
90
A convenience function for installing a content view as a subview of `backgroundView`
90
91
and pinning the edges to `backgroundView` with the specified `insets`.
91
-
92
+
92
93
- Parameter contentView: The view to be installed into the background view
93
- and assigned to the `contentView` property.
94
+ and assigned to the `contentView` property.
94
95
- Parameter insets: The amount to inset the content view from the background view.
95
- Default is zero inset.
96
+ Default is zero inset.
96
97
*/
97
98
open func installContentView( _ contentView: UIView , insets: UIEdgeInsets = UIEdgeInsets . zero) {
98
99
contentView. translatesAutoresizingMaskIntoConstraints = false
@@ -103,11 +104,11 @@ open class BaseView: UIView, BackgroundViewable, MarginAdjustable {
103
104
let right = NSLayoutConstraint ( item: contentView, attribute: . right, relatedBy: . equal, toItem: backgroundView, attribute: . right, multiplier: 1.0 , constant: - insets. right)
104
105
backgroundView. addConstraints ( [ top, left, bottom, right] )
105
106
}
106
-
107
+
107
108
/*
108
109
MARK: - Tap handler
109
110
*/
110
-
111
+
111
112
/**
112
113
An optional tap handler that will be called when the `backgroundView` is tapped.
113
114
*/
@@ -116,18 +117,19 @@ open class BaseView: UIView, BackgroundViewable, MarginAdjustable {
116
117
installTapRecognizer ( )
117
118
}
118
119
}
119
-
120
+
120
121
fileprivate lazy var tapRecognizer : UITapGestureRecognizer = {
121
122
let tapRecognizer = UITapGestureRecognizer ( target: self , action: #selector( MessageView . tapped) )
122
123
return tapRecognizer
123
124
} ( )
124
-
125
+
125
126
@objc func tapped( ) {
126
127
tapHandler ? ( self )
127
128
}
128
-
129
+
129
130
fileprivate func installTapRecognizer( ) {
130
131
guard let backgroundView = backgroundView else { return }
132
+ removeGestureRecognizer ( tapRecognizer)
131
133
backgroundView. removeGestureRecognizer ( tapRecognizer)
132
134
if tapHandler != nil {
133
135
// Only install the tap recognizer if there is a tap handler,
@@ -137,22 +139,30 @@ open class BaseView: UIView, BackgroundViewable, MarginAdjustable {
137
139
}
138
140
}
139
141
142
+ open override func point( inside point: CGPoint , with event: UIEvent ? ) -> Bool {
143
+ if backgroundView != self {
144
+ let backgroundViewPoint = convert ( point, to: backgroundView)
145
+ return backgroundView. point ( inside: backgroundViewPoint, with: event)
146
+ }
147
+ return super. point ( inside: point, with: event)
148
+ }
149
+
140
150
/*
141
151
MARK: - MarginAdjustable
142
-
152
+
143
153
These properties fulfill the `MarginAdjustable` protocol and are exposed
144
154
as `@IBInspectables` so that they can be adjusted directly in nib files
145
155
(see MessageView.nib).
146
156
*/
147
-
148
- @IBInspectable open var bounceAnimationOffset : CGFloat = 5.0
149
157
158
+ @IBInspectable open var bounceAnimationOffset : CGFloat = 5.0
159
+
150
160
/**
151
161
For iOS 10 and lower, an optional absolute value for the top margin for cases
152
162
where the view appears behind the status bar.
153
163
*/
154
164
@IBInspectable open var statusBarOffset : CGFloat = 20.0
155
-
165
+
156
166
/**
157
167
For iOS 11 and greater, an optional top margin adjustment for cases where the
158
168
view appears behind known safe zone elements, such as the status bar and the
@@ -173,7 +183,7 @@ open class BaseView: UIView, BackgroundViewable, MarginAdjustable {
173
183
/*
174
184
MARK: - Setting preferred height
175
185
*/
176
-
186
+
177
187
/**
178
188
An optional value that sets the message view's intrinsic content height.
179
189
This can be used as a way to specify a fixed height for the message view.
@@ -185,7 +195,7 @@ open class BaseView: UIView, BackgroundViewable, MarginAdjustable {
185
195
setNeedsLayout ( )
186
196
}
187
197
}
188
-
198
+
189
199
open override var intrinsicContentSize : CGSize {
190
200
if let preferredHeight = preferredHeight {
191
201
return CGSize ( width: UIViewNoIntrinsicMetric, height: preferredHeight)
@@ -199,7 +209,7 @@ open class BaseView: UIView, BackgroundViewable, MarginAdjustable {
199
209
*/
200
210
201
211
extension BaseView {
202
-
212
+
203
213
/// A convenience function to configure a default drop shadow effect.
204
214
open func configureDropShadow( ) {
205
215
let layer = backgroundView. layer
@@ -214,9 +224,10 @@ extension BaseView {
214
224
private func updateShadowPath( ) {
215
225
layer. shadowPath = UIBezierPath ( roundedRect: layer. bounds, cornerRadius: layer. cornerRadius) . cgPath
216
226
}
217
-
227
+
218
228
open override func layoutSubviews( ) {
219
229
super. layoutSubviews ( )
220
230
updateShadowPath ( )
221
231
}
222
232
}
233
+
0 commit comments