@@ -462,6 +462,7 @@ public class BubbleShowCase: UIView {
462
462
463
463
// Updates bubble top and bottom constraints to make fit the bubble into the screen. It should be called once the subviews have been rendered.
464
464
private func updateSideConstraints( ) {
465
+ guard let bubble = bubble else { return }
465
466
let topAvailableSpace = screenshotContainer. frame. midY - margins
466
467
let bottomAvailableSpace = screenWindow. frame. height - screenshotContainer. frame. midY - margins
467
468
if topAvailableSpace < bubble. frame. height / 2 {
@@ -598,12 +599,15 @@ public class BubbleShowCase: UIView {
598
599
bubbleTrailing? . constant = ( bubbleTrailing? . constant ?? 0 ) - safeAreaMargins. left
599
600
case . portraitUpsideDown, . faceUp, . faceDown, . unknown:
600
601
break
602
+ @unknown default :
603
+ break
601
604
}
602
605
}
603
606
604
607
// Creates a button, draws a cross inside and places it at the top right of the bubble
605
608
private func drawCross( ) {
606
- cross = UIButton ( )
609
+ let cross = UIButton ( )
610
+ self . cross = cross
607
611
cross. addTarget ( self , action: #selector( crossDidTap) , for: . touchUpInside)
608
612
cross. translatesAutoresizingMaskIntoConstraints = false
609
613
bubble. addSubview ( cross)
@@ -638,7 +642,8 @@ public class BubbleShowCase: UIView {
638
642
private func drawArrow( ) {
639
643
guard arrowDirection != . none else { return }
640
644
641
- arrow = UIView ( )
645
+ let arrow = UIView ( )
646
+ self . arrow = arrow
642
647
arrow. translatesAutoresizingMaskIntoConstraints = false
643
648
bubble. addSubview ( arrow)
644
649
@@ -725,10 +730,10 @@ public class BubbleShowCase: UIView {
725
730
arrow2. translatesAutoresizingMaskIntoConstraints = false
726
731
bubble. addSubview ( arrow2)
727
732
728
- let bottom2 = NSLayoutConstraint ( item: arrow2, attribute: . bottom, relatedBy: . equal, toItem: bubble, attribute: . bottom, multiplier: 1 , constant: arrowSize)
729
- let centerX2 = NSLayoutConstraint ( item: arrow2, attribute: . centerX, relatedBy: . equal, toItem: self , attribute: . centerX, multiplier: 1 , constant: - arrowSize)
730
- let height2 = NSLayoutConstraint ( item: arrow2, attribute: . height, relatedBy: . equal, toItem: nil , attribute: . height, multiplier: 1 , constant: arrowSize)
731
- let width2 = NSLayoutConstraint ( item: arrow2, attribute: . width, relatedBy: . equal, toItem: nil , attribute: . width, multiplier: 1 , constant: 2 * arrowSize)
733
+ let bottom2 = NSLayoutConstraint ( item: arrow2! , attribute: . bottom, relatedBy: . equal, toItem: bubble, attribute: . bottom, multiplier: 1 , constant: arrowSize)
734
+ let centerX2 = NSLayoutConstraint ( item: arrow2! , attribute: . centerX, relatedBy: . equal, toItem: self , attribute: . centerX, multiplier: 1 , constant: - arrowSize)
735
+ let height2 = NSLayoutConstraint ( item: arrow2! , attribute: . height, relatedBy: . equal, toItem: nil , attribute: . height, multiplier: 1 , constant: arrowSize)
736
+ let width2 = NSLayoutConstraint ( item: arrow2! , attribute: . width, relatedBy: . equal, toItem: nil , attribute: . width, multiplier: 1 , constant: 2 * arrowSize)
732
737
733
738
bubble. addConstraint ( bottom2)
734
739
addConstraint ( centerX2)
@@ -758,10 +763,10 @@ public class BubbleShowCase: UIView {
758
763
arrow2. translatesAutoresizingMaskIntoConstraints = false
759
764
bubble. addSubview ( arrow2)
760
765
761
- let centerY2 = NSLayoutConstraint ( item: arrow2, attribute: . centerY, relatedBy: . equal, toItem: self , attribute: . centerY, multiplier: 1 , constant: - arrowSize)
762
- let trailing2 = NSLayoutConstraint ( item: arrow2, attribute: . trailing, relatedBy: . equal, toItem: bubble, attribute: . trailing, multiplier: 1 , constant: arrowSize)
763
- let height2 = NSLayoutConstraint ( item: arrow2, attribute: . height, relatedBy: . equal, toItem: nil , attribute: . height, multiplier: 1 , constant: 2 * arrowSize)
764
- let width2 = NSLayoutConstraint ( item: arrow2, attribute: . width, relatedBy: . equal, toItem: nil , attribute: . width, multiplier: 1 , constant: arrowSize)
766
+ let centerY2 = NSLayoutConstraint ( item: arrow2! , attribute: . centerY, relatedBy: . equal, toItem: self , attribute: . centerY, multiplier: 1 , constant: - arrowSize)
767
+ let trailing2 = NSLayoutConstraint ( item: arrow2! , attribute: . trailing, relatedBy: . equal, toItem: bubble, attribute: . trailing, multiplier: 1 , constant: arrowSize)
768
+ let height2 = NSLayoutConstraint ( item: arrow2! , attribute: . height, relatedBy: . equal, toItem: nil , attribute: . height, multiplier: 1 , constant: 2 * arrowSize)
769
+ let width2 = NSLayoutConstraint ( item: arrow2! , attribute: . width, relatedBy: . equal, toItem: nil , attribute: . width, multiplier: 1 , constant: arrowSize)
765
770
766
771
bubble. addConstraint ( trailing2)
767
772
addConstraint ( centerY2)
@@ -956,7 +961,8 @@ public class BubbleShowCase: UIView {
956
961
957
962
// Embeds the screenshot in the show case
958
963
private func embedScreenshot( ) {
959
- screenshotContainer = UIView ( )
964
+ let screenshotContainer = UIView ( )
965
+ self . screenshotContainer = screenshotContainer
960
966
screenshotContainer. translatesAutoresizingMaskIntoConstraints = false
961
967
addSubview ( screenshotContainer)
962
968
addGestureRecognizersToScreenshot ( )
@@ -1037,7 +1043,8 @@ public class BubbleShowCase: UIView {
1037
1043
1038
1044
// Embeds the bubble in the show case view and places it next to the target according to the arrow direction
1039
1045
private func embedBubble( ) {
1040
- bubble = UIView ( )
1046
+ let bubble = UIView ( )
1047
+ self . bubble = bubble
1041
1048
bubble. layer. cornerRadius = 5
1042
1049
bubble. clipsToBounds = false
1043
1050
bubble. translatesAutoresizingMaskIntoConstraints = false
@@ -1057,7 +1064,8 @@ public class BubbleShowCase: UIView {
1057
1064
}
1058
1065
1059
1066
private func embedSkipButton( ) {
1060
- skipLabel = UILabel ( )
1067
+ let skipLabel = UILabel ( )
1068
+ self . skipLabel = skipLabel
1061
1069
skipLabel. textColor = UIColor . white
1062
1070
skipLabel. text = skipButtonText
1063
1071
skipLabel. textAlignment = . center
@@ -1079,7 +1087,6 @@ public class BubbleShowCase: UIView {
1079
1087
1080
1088
addConstraint ( centerX)
1081
1089
addConstraint ( bottom)
1082
-
1083
1090
}
1084
1091
1085
1092
private func addGestureRecognizerToSkipButton( ) {
@@ -1095,6 +1102,7 @@ public class BubbleShowCase: UIView {
1095
1102
1096
1103
// Constraints the bubble to the target for both leftAndSide and upAndDown arrow directions
1097
1104
private func constraintBubbleForDoubleDirections( ) {
1105
+ guard let bubble = bubble else { return }
1098
1106
let centerY = NSLayoutConstraint ( item: bubble, attribute: . centerY, relatedBy: . equal, toItem: self , attribute: . centerY, multiplier: 1 , constant: 0 )
1099
1107
let centerX = NSLayoutConstraint ( item: bubble, attribute: . centerX, relatedBy: . equal, toItem: self , attribute: . centerX, multiplier: 1 , constant: 0 )
1100
1108
addConstraints ( [ centerY, centerX] )
@@ -1112,6 +1120,7 @@ public class BubbleShowCase: UIView {
1112
1120
1113
1121
// Constraints the bubble to the target for both left and right arrow directions
1114
1122
private func contraintBubbleForSideDirections( ) {
1123
+ guard let bubble = bubble else { return }
1115
1124
let centerY = NSLayoutConstraint ( item: bubble, attribute: . centerY, relatedBy: . equal, toItem: screenshotContainer, attribute: . centerY, multiplier: 1 , constant: 0 )
1116
1125
addConstraint ( centerY)
1117
1126
sideShowCaseCenterY = centerY
@@ -1143,6 +1152,7 @@ public class BubbleShowCase: UIView {
1143
1152
1144
1153
// Constraints the bubble to the target for both up and down arrow directions
1145
1154
private func constraintBubbleForTopDirections( ) {
1155
+ guard let bubble = bubble else { return }
1146
1156
if arrowDirection == . up {
1147
1157
let topConstant = margins + padding
1148
1158
let top = NSLayoutConstraint ( item: bubble, attribute: . top, relatedBy: . equal, toItem: screenshotContainer, attribute: . bottom, multiplier: 1 , constant: topConstant)
@@ -1193,14 +1203,16 @@ public class BubbleShowCase: UIView {
1193
1203
1194
1204
// Embeds both the title and description into the show case
1195
1205
private func embedLabels( ) {
1196
- titleLabel = UILabel ( )
1206
+ let titleLabel = UILabel ( )
1207
+ self . titleLabel = titleLabel
1197
1208
titleLabel. numberOfLines = 0
1198
1209
titleLabel. text = titleText
1199
1210
titleLabel. font = titleFont
1200
1211
titleLabel. translatesAutoresizingMaskIntoConstraints = false
1201
1212
bubble. addSubview ( titleLabel)
1202
1213
1203
- descriptionLabel = UILabel ( )
1214
+ let descriptionLabel = UILabel ( )
1215
+ self . descriptionLabel = descriptionLabel
1204
1216
descriptionLabel. numberOfLines = 0
1205
1217
descriptionLabel. text = descriptionText
1206
1218
descriptionLabel. font = descriptionFont
@@ -1222,20 +1234,21 @@ public class BubbleShowCase: UIView {
1222
1234
1223
1235
// Embeds the icon in the show case, shifting the labels rightwards
1224
1236
private func embedImage( ) {
1225
- icon = UIImageView ( image: image)
1226
- icon? . translatesAutoresizingMaskIntoConstraints = false
1227
- bubble. addSubview ( icon!)
1237
+ let icon = UIImageView ( image: image)
1238
+ self . icon = icon
1239
+ icon. translatesAutoresizingMaskIntoConstraints = false
1240
+ bubble. addSubview ( icon)
1228
1241
1229
- let height = NSLayoutConstraint ( item: icon! , attribute: . height, relatedBy: . equal, toItem: nil , attribute: . height, multiplier: 1 , constant: imageSize. height)
1230
- let width = NSLayoutConstraint ( item: icon! , attribute: . width, relatedBy: . equal, toItem: nil , attribute: . width, multiplier: 1 , constant: imageSize. width)
1231
- icon? . addConstraints ( [ height, width] )
1242
+ let height = NSLayoutConstraint ( item: icon, attribute: . height, relatedBy: . equal, toItem: nil , attribute: . height, multiplier: 1 , constant: imageSize. height)
1243
+ let width = NSLayoutConstraint ( item: icon, attribute: . width, relatedBy: . equal, toItem: nil , attribute: . width, multiplier: 1 , constant: imageSize. width)
1244
+ icon. addConstraints ( [ height, width] )
1232
1245
1233
- let leading = NSLayoutConstraint ( item: icon! , attribute: . leading, relatedBy: . equal, toItem: bubble, attribute: . leading, multiplier: 1 , constant: bubblePadding. left)
1234
- let centerY = NSLayoutConstraint ( item: icon! , attribute: . centerY, relatedBy: . equal, toItem: bubble, attribute: . centerY, multiplier: 1 , constant: 0 )
1246
+ let leading = NSLayoutConstraint ( item: icon, attribute: . leading, relatedBy: . equal, toItem: bubble, attribute: . leading, multiplier: 1 , constant: bubblePadding. left)
1247
+ let centerY = NSLayoutConstraint ( item: icon, attribute: . centerY, relatedBy: . equal, toItem: bubble, attribute: . centerY, multiplier: 1 , constant: 0 )
1235
1248
bubble. addConstraints ( [ leading, centerY] )
1236
1249
1237
1250
bubble. removeConstraint ( descriptionLeading)
1238
- descriptionLeading = NSLayoutConstraint ( item: descriptionLabel, attribute: . leading, relatedBy: . equal, toItem: icon! , attribute: . trailing, multiplier: 1 , constant: 15 )
1251
+ descriptionLeading = NSLayoutConstraint ( item: descriptionLabel! , attribute: . leading, relatedBy: . equal, toItem: icon, attribute: . trailing, multiplier: 1 , constant: 15 )
1239
1252
bubble. addConstraint ( descriptionLeading)
1240
1253
}
1241
1254
0 commit comments