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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
//
// Popover.swift
// Popover
//
// Created by corin8823 on 8/16/15.
// Copyright (c) 2015 corin8823. All rights reserved.
//
import Foundation
import UIKit
public enum PopoverOption {
case arrowSize(CGSize)
case animationIn(TimeInterval)
case animationOut(TimeInterval)
case cornerRadius(CGFloat)
case sideEdge(CGFloat)
case blackOverlayColor(UIColor)
case overlayBlur(UIBlurEffect.Style)
case type(PopoverType)
case color(UIColor)
case dismissOnBlackOverlayTap(Bool)
case showBlackOverlay(Bool)
case springDamping(CGFloat)
case initialSpringVelocity(CGFloat)
case sideOffset(CGFloat)
case borderColor(UIColor)
}
@objc public enum PopoverType: Int {
case up
case down
case left
case right
case auto
}
@objcMembers
open class Popover: UIView {
// custom property
open var arrowSize: CGSize = CGSize(width: 16.0, height: 10.0)
open var animationIn: TimeInterval = 0.6
open var animationOut: TimeInterval = 0.3
open var cornerRadius: CGFloat = 6.0
open var sideEdge: CGFloat = 20.0
open var popoverType: PopoverType = .down
open var blackOverlayColor: UIColor = UIColor(white: 0.0, alpha: 0.2)
open var overlayBlur: UIBlurEffect?
open var popoverColor: UIColor = UIColor.white
open var dismissOnBlackOverlayTap: Bool = true
open var showBlackOverlay: Bool = true
open var highlightFromView: Bool = false
open var highlightCornerRadius: CGFloat = 0
open var springDamping: CGFloat = 0.7
open var initialSpringVelocity: CGFloat = 3
open var sideOffset: CGFloat = 6.0
open var borderColor: UIColor?
// custom closure
open var willShowHandler: (() -> ())?
open var willDismissHandler: (() -> ())?
open var didShowHandler: (() -> ())?
open var didDismissHandler: (() -> ())?
public fileprivate(set) var blackOverlay: UIControl = UIControl()
fileprivate var containerView: UIView!
fileprivate var contentView: UIView!
fileprivate var contentViewFrame: CGRect!
fileprivate var arrowShowPoint: CGPoint!
public init() {
super.init(frame: .zero)
self.backgroundColor = .clear
self.accessibilityViewIsModal = true
}
public init(showHandler: (() -> ())?, dismissHandler: (() -> ())?) {
super.init(frame: .zero)
self.backgroundColor = .clear
self.didShowHandler = showHandler
self.didDismissHandler = dismissHandler
self.accessibilityViewIsModal = true
}
public init(options: [PopoverOption]?, showHandler: (() -> ())? = nil, dismissHandler: (() -> ())? = nil) {
super.init(frame: .zero)
self.backgroundColor = .clear
self.setOptions(options)
self.didShowHandler = showHandler
self.didDismissHandler = dismissHandler
self.accessibilityViewIsModal = true
}
required public init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override open func layoutSubviews() {
super.layoutSubviews()
self.contentView.frame = self.bounds
}
open func showAsDialog(_ contentView: UIView) {
guard let rootView = UIApplication.shared.keyWindow else {
return
}
self.showAsDialog(contentView, inView: rootView)
}
open func showAsDialog(_ contentView: UIView, inView: UIView) {
self.arrowSize = .zero
let point = CGPoint(x: inView.center.x,
y: inView.center.y - contentView.frame.height / 2)
self.show(contentView, point: point, inView: inView)
}
open func show(_ contentView: UIView, fromView: UIView) {
guard let rootView = UIApplication.shared.keyWindow else {
return
}
self.show(contentView, fromView: fromView, inView: rootView)
}
open func show(_ contentView: UIView, fromView: UIView, inView: UIView) {
let point: CGPoint
//TODO: add left/right auto
if self.popoverType == .auto {
if let point = fromView.superview?.convert(fromView.frame.origin, to: nil),
point.y + fromView.frame.height + self.arrowSize.height + contentView.frame.height > inView.frame.height {
self.popoverType = .up
} else {
self.popoverType = .down
}
}
switch self.popoverType {
case .up:
point = inView.convert(
CGPoint(
x: fromView.frame.origin.x + (fromView.frame.size.width / 2),
y: fromView.frame.origin.y
), from: fromView.superview)
case .down, .auto:
point = inView.convert(
CGPoint(
x: fromView.frame.origin.x + (fromView.frame.size.width / 2),
y: fromView.frame.origin.y + fromView.frame.size.height
), from: fromView.superview)
case .left:
point = inView.convert(
CGPoint(x: fromView.frame.origin.x - sideOffset,
y: fromView.frame.origin.y + 0.5 * fromView.frame.height
), from: fromView.superview)
case .right:
point = inView.convert(
CGPoint(x: fromView.frame.origin.x + fromView.frame.size.width + sideOffset,
y: fromView.frame.origin.y + 0.5 * fromView.frame.height
), from: fromView.superview)
}
if self.highlightFromView {
self.createHighlightLayer(fromView: fromView, inView: inView)
}
self.show(contentView, point: point, inView: inView)
}
open func show(_ contentView: UIView, point: CGPoint) {
guard let rootView = UIApplication.shared.keyWindow else {
return
}
self.show(contentView, point: point, inView: rootView)
}
open func show(_ contentView: UIView, point: CGPoint, inView: UIView) {
if self.dismissOnBlackOverlayTap || self.showBlackOverlay {
self.blackOverlay.autoresizingMask = [.flexibleWidth, .flexibleHeight]
self.blackOverlay.frame = inView.bounds
inView.addSubview(self.blackOverlay)
if showBlackOverlay {
if let overlayBlur = self.overlayBlur {
let effectView = UIVisualEffectView(effect: overlayBlur)
effectView.frame = self.blackOverlay.bounds
effectView.isUserInteractionEnabled = false
self.blackOverlay.addSubview(effectView)
} else {
if !self.highlightFromView {
self.blackOverlay.backgroundColor = self.blackOverlayColor
}
self.blackOverlay.alpha = 0
}
}
if self.dismissOnBlackOverlayTap {
self.blackOverlay.addTarget(self, action: #selector(Popover.dismiss), for: .touchUpInside)
}
}
self.containerView = inView
self.contentView = contentView
self.contentView.backgroundColor = UIColor.clear
self.contentView.layer.cornerRadius = self.cornerRadius
self.contentView.layer.masksToBounds = true
self.arrowShowPoint = point
self.show()
}
open override func accessibilityPerformEscape() -> Bool {
self.dismiss()
return true
}
@objc open func dismiss() {
if self.superview != nil {
self.willDismissHandler?()
UIView.animate(withDuration: self.animationOut, delay: 0,
options: UIView.AnimationOptions(),
animations: {
self.transform = CGAffineTransform(scaleX: 0.0001, y: 0.0001)
self.blackOverlay.alpha = 0
}){ _ in
self.contentView.removeFromSuperview()
self.blackOverlay.removeFromSuperview()
self.removeFromSuperview()
self.transform = CGAffineTransform.identity
self.didDismissHandler?()
}
}
}
override open func draw(_ rect: CGRect) {
super.draw(rect)
let arrow = UIBezierPath()
let color = self.popoverColor
let arrowPoint = self.containerView.convert(self.arrowShowPoint, to: self)
switch self.popoverType {
case .up:
arrow.move(to: CGPoint(x: arrowPoint.x, y: self.bounds.height))
arrow.addLine(
to: CGPoint(
x: arrowPoint.x - self.arrowSize.width * 0.5,
y: self.isCornerLeftArrow ? self.arrowSize.height : self.bounds.height - self.arrowSize.height
)
)
arrow.addLine(to: CGPoint(x: self.cornerRadius, y: self.bounds.height - self.arrowSize.height))
arrow.addArc(
withCenter: CGPoint(
x: self.cornerRadius,
y: self.bounds.height - self.arrowSize.height - self.cornerRadius
),
radius: self.cornerRadius,
startAngle: self.radians(90),
endAngle: self.radians(180),
clockwise: true)
arrow.addLine(to: CGPoint(x: 0, y: self.cornerRadius))
arrow.addArc(
withCenter: CGPoint(
x: self.cornerRadius,
y: self.cornerRadius
),
radius: self.cornerRadius,
startAngle: self.radians(180),
endAngle: self.radians(270),
clockwise: true)
arrow.addLine(to: CGPoint(x: self.bounds.width - self.cornerRadius, y: 0))
arrow.addArc(
withCenter: CGPoint(
x: self.bounds.width - self.cornerRadius,
y: self.cornerRadius
),
radius: self.cornerRadius,
startAngle: self.radians(270),
endAngle: self.radians(0),
clockwise: true)
arrow.addLine(to: CGPoint(x: self.bounds.width, y: self.bounds.height - self.arrowSize.height - self.cornerRadius))
arrow.addArc(
withCenter: CGPoint(
x: self.bounds.width - self.cornerRadius,
y: self.bounds.height - self.arrowSize.height - self.cornerRadius
),
radius: self.cornerRadius,
startAngle: self.radians(0),
endAngle: self.radians(90),
clockwise: true)
arrow.addLine(
to: CGPoint(
x: arrowPoint.x + self.arrowSize.width * 0.5,
y: self.isCornerRightArrow ? self.arrowSize.height : self.bounds.height - self.arrowSize.height
)
)
case .down, .auto:
arrow.move(to: CGPoint(x: arrowPoint.x, y: 0))
if self.isCloseToCornerRightArrow && !self.isCornerRightArrow {
if !isBehindCornerRightArrow {
arrow.addLine(to: CGPoint(x: self.bounds.width - self.cornerRadius, y: self.arrowSize.height))
arrow.addArc(
withCenter: CGPoint(x: self.bounds.width - self.cornerRadius, y: self.arrowSize.height + self.cornerRadius),
radius: self.cornerRadius,
startAngle: self.radians(270.0),
endAngle: self.radians(0),
clockwise: true)
} else {
arrow.addLine(to: CGPoint(x: self.bounds.width, y: self.arrowSize.height + self.cornerRadius))
arrow.addLine(to: CGPoint(x: self.bounds.width, y: self.arrowSize.height))
}
} else {
arrow.addLine(
to: CGPoint(
x: self.isBehindCornerLeftArrow ? self.frame.minX - self.arrowSize.width * 0.5 : arrowPoint.x + self.arrowSize.width * 0.5,
y: self.isCornerRightArrow ? self.arrowSize.height + self.bounds.height : self.arrowSize.height
)
)
arrow.addLine(to: CGPoint(x: self.bounds.width - self.cornerRadius, y: self.arrowSize.height))
arrow.addArc(
withCenter: CGPoint(
x: self.bounds.width - self.cornerRadius,
y: self.arrowSize.height + self.cornerRadius
),
radius: self.cornerRadius,
startAngle: self.radians(270.0),
endAngle: self.radians(0),
clockwise: true)
}
arrow.addLine(to: CGPoint(x: self.bounds.width, y: self.bounds.height - self.cornerRadius))
arrow.addArc(
withCenter: CGPoint(
x: self.bounds.width - self.cornerRadius,
y: self.bounds.height - self.cornerRadius
),
radius: self.cornerRadius,
startAngle: self.radians(0),
endAngle: self.radians(90),
clockwise: true)
arrow.addLine(to: CGPoint(x: 0, y: self.bounds.height))
arrow.addArc(
withCenter: CGPoint(
x: self.cornerRadius,
y: self.bounds.height - self.cornerRadius
),
radius: self.cornerRadius,
startAngle: self.radians(90),
endAngle: self.radians(180),
clockwise: true)
arrow.addLine(to: CGPoint(x: 0, y: self.arrowSize.height + self.cornerRadius))
if !isBehindCornerLeftArrow {
arrow.addArc(
withCenter: CGPoint(
x: self.cornerRadius,
y: self.arrowSize.height + self.cornerRadius
),
radius: self.cornerRadius,
startAngle: self.radians(180),
endAngle: self.radians(270),
clockwise: true)
}
if isBehindCornerRightArrow {
arrow.addLine(to: CGPoint(
x: self.bounds.width - self.arrowSize.width * 0.5,
y: self.isCornerLeftArrow ? self.arrowSize.height + self.bounds.height : self.arrowSize.height))
} else if isCloseToCornerLeftArrow && !isCornerLeftArrow {
() // skipping this line in that case
} else {
arrow.addLine(to: CGPoint(x: arrowPoint.x - self.arrowSize.width * 0.5,
y: self.isCornerLeftArrow ? self.arrowSize.height + self.bounds.height : self.arrowSize.height))
}
case .left:
arrow.move(to: CGPoint(x: self.bounds.width, y: self.bounds.height * 0.5))
arrow.addLine(
to: CGPoint(
x: self.bounds.width - self.arrowSize.height,
y: self.bounds.height * 0.5 + self.arrowSize.width * 0.5
))
arrow.addLine(to: CGPoint(x:self.bounds.width - self.arrowSize.height, y: self.bounds.height - self.cornerRadius))
arrow.addArc(
withCenter: CGPoint(
x: self.bounds.width - self.arrowSize.height - self.cornerRadius,
y: self.bounds.height - self.cornerRadius
),
radius: self.cornerRadius,
startAngle: self.radians(0.0),
endAngle: self.radians(90),
clockwise: true)
arrow.addLine(to: CGPoint(x: self.cornerRadius, y: self.bounds.height))
arrow.addArc(
withCenter: CGPoint(
x: self.cornerRadius,
y: self.bounds.height - self.cornerRadius
),
radius: self.cornerRadius,
startAngle: self.radians(90),
endAngle: self.radians(180),
clockwise: true)
arrow.addLine(to: CGPoint(x: 0, y: self.cornerRadius))
arrow.addArc(
withCenter: CGPoint(
x: self.cornerRadius,
y: self.cornerRadius
),
radius: self.cornerRadius,
startAngle: self.radians(180),
endAngle: self.radians(270),
clockwise: true)
arrow.addLine(to: CGPoint(x: self.bounds.width - self.arrowSize.height - self.cornerRadius, y: 0))
arrow.addArc(
withCenter: CGPoint(x: self.bounds.width - self.arrowSize.height - self.cornerRadius,
y: self.cornerRadius
),
radius: self.cornerRadius,
startAngle: self.radians(270),
endAngle: self.radians(0),
clockwise: true)
arrow.addLine(to: CGPoint(x: self.bounds.width - self.arrowSize.height,
y: self.bounds.height * 0.5 - self.arrowSize.width * 0.5
))
case .right:
arrow.move(to: CGPoint(x: arrowPoint.x, y: self.bounds.height * 0.5))
arrow.addLine(
to: CGPoint(
x: arrowPoint.x + self.arrowSize.height,
y: self.bounds.height * 0.5 + 0.5 * self.arrowSize.width
))
arrow.addLine(
to: CGPoint(
x: arrowPoint.x + self.arrowSize.height,
y: self.bounds.height - self.cornerRadius
))
arrow.addArc(
withCenter: CGPoint(
x: arrowPoint.x + self.arrowSize.height + self.cornerRadius,
y: self.bounds.height - self.cornerRadius
),
radius: self.cornerRadius,
startAngle: self.radians(180.0),
endAngle: self.radians(90),
clockwise: false)
arrow.addLine(to: CGPoint(x: self.bounds.width + arrowPoint.x - self.cornerRadius, y: self.bounds.height))
arrow.addArc(
withCenter: CGPoint(
x: self.bounds.width + arrowPoint.x - self.cornerRadius,
y: self.bounds.height - self.cornerRadius
),
radius: self.cornerRadius,
startAngle: self.radians(90),
endAngle: self.radians(0),
clockwise: false)
arrow.addLine(to: CGPoint(x: self.bounds.width + arrowPoint.x, y: self.cornerRadius))
arrow.addArc(
withCenter: CGPoint(
x: self.bounds.width + arrowPoint.x - self.cornerRadius,
y: self.cornerRadius
),
radius: self.cornerRadius,
startAngle: self.radians(0),
endAngle: self.radians(-90),
clockwise: false)
arrow.addLine(to: CGPoint(x: arrowPoint.x + self.arrowSize.height - self.cornerRadius, y: 0))
arrow.addArc(
withCenter: CGPoint(x: arrowPoint.x + self.arrowSize.height + self.cornerRadius,
y: self.cornerRadius
),
radius: self.cornerRadius,
startAngle: self.radians(-90),
endAngle: self.radians(-180),
clockwise: false)
arrow.addLine(to: CGPoint(x: arrowPoint.x + self.arrowSize.height,
y: self.bounds.height * 0.5 - self.arrowSize.width * 0.5))
}
color.setFill()
arrow.fill()
if let borderColor = borderColor {
borderColor.setStroke()
arrow.stroke()
}
}
}
private extension Popover {
func setOptions(_ options: [PopoverOption]?){
if let options = options {
for option in options {
switch option {
case let .arrowSize(value):
self.arrowSize = value
case let .animationIn(value):
self.animationIn = value
case let .animationOut(value):
self.animationOut = value
case let .cornerRadius(value):
self.cornerRadius = value
case let .sideEdge(value):
self.sideEdge = value
case let .blackOverlayColor(value):
self.blackOverlayColor = value
case let .overlayBlur(style):
self.overlayBlur = UIBlurEffect(style: style)
case let .type(value):
self.popoverType = value
case let .color(value):
self.popoverColor = value
case let .dismissOnBlackOverlayTap(value):
self.dismissOnBlackOverlayTap = value
case let .showBlackOverlay(value):
self.showBlackOverlay = value
case let .springDamping(value):
self.springDamping = value
case let .initialSpringVelocity(value):
self.initialSpringVelocity = value
case let .sideOffset(value):
self.sideOffset = value
case let .borderColor(value):
self.borderColor = value
}
}
}
}
func create() {
var frame = self.contentView.frame
switch self.popoverType {
case .up, .down, .auto:
frame.origin.x = self.arrowShowPoint.x - frame.size.width * 0.5
case .left, .right:
frame.origin.y = self.arrowShowPoint.y - frame.size.height * 0.5
}
var sideEdge: CGFloat = 0.0
if frame.size.width < self.containerView.frame.size.width {
sideEdge = self.sideEdge
}
let outerSideEdge = frame.maxX - self.containerView.bounds.size.width
if outerSideEdge > 0 {
frame.origin.x -= (outerSideEdge + sideEdge)
} else {
if frame.minX < 0 {
frame.origin.x += abs(frame.minX) + sideEdge
}
}
self.frame = frame
let arrowPoint = self.containerView.convert(self.arrowShowPoint, to: self)
var anchorPoint: CGPoint
switch self.popoverType {
case .up:
frame.origin.y = self.arrowShowPoint.y - frame.height - self.arrowSize.height
anchorPoint = CGPoint(x: arrowPoint.x / frame.size.width, y: 1)
case .down, .auto:
frame.origin.y = self.arrowShowPoint.y
anchorPoint = CGPoint(x: arrowPoint.x / frame.size.width, y: 0)
case .left:
frame.origin.x = self.arrowShowPoint.x - frame.size.width - self.arrowSize.height
anchorPoint = CGPoint(x: 1, y: 0.5)
case .right:
frame.origin.x = self.arrowShowPoint.x
anchorPoint = CGPoint(x: 0, y: 0.5)
}
if self.arrowSize == .zero {
anchorPoint = CGPoint(x: 0.5, y: 0.5)
}
let lastAnchor = self.layer.anchorPoint
self.layer.anchorPoint = anchorPoint
let x = self.layer.position.x + (anchorPoint.x - lastAnchor.x) * self.layer.bounds.size.width
let y = self.layer.position.y + (anchorPoint.y - lastAnchor.y) * self.layer.bounds.size.height
self.layer.position = CGPoint(x: x, y: y)
switch self.popoverType {
case .up, .down, .auto:
frame.size.height += self.arrowSize.height
case .left, .right:
frame.size.width += self.arrowSize.height
}
self.frame = frame
}
func createHighlightLayer(fromView: UIView, inView: UIView) {
let path = UIBezierPath(rect: inView.bounds)
let highlightRect = inView.convert(fromView.frame, from: fromView.superview)
let highlightPath = UIBezierPath(roundedRect: highlightRect, cornerRadius: self.highlightCornerRadius)
path.append(highlightPath)
path.usesEvenOddFillRule = true
let fillLayer = CAShapeLayer()
fillLayer.path = path.cgPath
fillLayer.fillRule = CAShapeLayerFillRule.evenOdd
fillLayer.fillColor = self.blackOverlayColor.cgColor
self.blackOverlay.layer.addSublayer(fillLayer)
}
func show() {
self.setNeedsDisplay()
switch self.popoverType {
case .up:
self.contentView.frame.origin.y = 0.0
case .down, .auto:
self.contentView.frame.origin.y = self.arrowSize.height
case .left, .right:
self.contentView.frame.origin.x = 0
}
self.addSubview(self.contentView)
self.containerView.addSubview(self)
self.create()
self.transform = CGAffineTransform(scaleX: 0.0, y: 0.0)
self.willShowHandler?()
UIView.animate(
withDuration: self.animationIn,
delay: 0,
usingSpringWithDamping: self.springDamping,
initialSpringVelocity: self.initialSpringVelocity,
options: UIView.AnimationOptions(),
animations: {
self.transform = CGAffineTransform.identity
}){ _ in
self.didShowHandler?()
}
UIView.animate(
withDuration: self.animationIn / 3,
delay: 0,
options: .curveLinear,
animations: {
self.blackOverlay.alpha = 1
}, completion: nil)
}
var isCloseToCornerLeftArrow: Bool {
return self.arrowShowPoint.x < self.frame.origin.x + arrowSize.width/2 + cornerRadius
}
var isCloseToCornerRightArrow: Bool {
return self.arrowShowPoint.x > (self.frame.origin.x + self.bounds.width) - arrowSize.width/2 - cornerRadius
}
var isCornerLeftArrow: Bool {
return self.arrowShowPoint.x == self.frame.origin.x
}
var isCornerRightArrow: Bool {
return self.arrowShowPoint.x == self.frame.origin.x + self.bounds.width
}
var isBehindCornerLeftArrow: Bool {
return self.arrowShowPoint.x < self.frame.origin.x
}
var isBehindCornerRightArrow: Bool {
return self.arrowShowPoint.x > self.frame.origin.x + self.bounds.width
}
func radians(_ degrees: CGFloat) -> CGFloat {
return CGFloat.pi * degrees / 180
}
}