@@ -14,7 +14,7 @@ import AVFoundation
1414/// The container for asset (video or image). It containts the YPGridView and YPAssetZoomableView.
1515class YPAssetViewContainer : UIView {
1616 public var zoomableView : YPAssetZoomableView ?
17- public let grid = YPGridView ( )
17+ public var itemOverlay : UIView ?
1818 public let curtain = UIView ( )
1919 public let spinnerView = UIView ( )
2020 public let squareCropButton = UIButton ( )
@@ -26,12 +26,25 @@ class YPAssetViewContainer: UIView {
2626 private var shouldCropToSquare = YPConfig . library. isSquareByDefault
2727 private var isMultipleSelection = false
2828
29+ public var itemOverlayType = YPConfig . library. itemOverlayType
30+
2931 override func awakeFromNib( ) {
3032 super. awakeFromNib ( )
3133
32- addSubview ( grid)
33- grid. frame = frame
34- clipsToBounds = true
34+ switch itemOverlayType {
35+ case . grid:
36+ itemOverlay = YPGridView ( )
37+ default :
38+ break
39+ }
40+
41+ if let itemOverlay = itemOverlay {
42+ addSubview ( itemOverlay)
43+ itemOverlay. frame = frame
44+ clipsToBounds = true
45+
46+ itemOverlay. alpha = 0
47+ }
3548
3649 for sv in subviews {
3750 if let cv = sv as? YPAssetZoomableView {
@@ -40,8 +53,6 @@ class YPAssetViewContainer: UIView {
4053 }
4154 }
4255
43- grid. alpha = 0
44-
4556 let touchDownGR = UILongPressGestureRecognizer ( target: self ,
4657 action: #selector( handleTouchDown) )
4758 touchDownGR. minimumPressDuration = 0
@@ -126,9 +137,11 @@ extension YPAssetViewContainer: YPAssetZoomableViewDelegate {
126137 public func ypAssetZoomableViewDidLayoutSubviews( _ zoomableView: YPAssetZoomableView ) {
127138 let newFrame = zoomableView. assetImageView. convert ( zoomableView. assetImageView. bounds, to: self )
128139
129- // update grid position
130- grid. frame = frame. intersection ( newFrame)
131- grid. layoutIfNeeded ( )
140+ if let itemOverlay = itemOverlay {
141+ // update grid position
142+ itemOverlay. frame = frame. intersection ( newFrame)
143+ itemOverlay. layoutIfNeeded ( )
144+ }
132145
133146 // Update play imageView position - bringing the playImageView from the videoView to assetViewContainer,
134147 // but the controll for appearing it still in videoView.
@@ -139,16 +152,22 @@ extension YPAssetViewContainer: YPAssetZoomableViewDelegate {
139152 }
140153
141154 public func ypAssetZoomableViewScrollViewDidZoom( ) {
155+ guard let itemOverlay = itemOverlay else {
156+ return
157+ }
142158 if isShown {
143159 UIView . animate ( withDuration: 0.1 ) {
144- self . grid . alpha = 1
160+ itemOverlay . alpha = 1
145161 }
146162 }
147163 }
148164
149165 public func ypAssetZoomableViewScrollViewDidEndZooming( ) {
166+ guard let itemOverlay = itemOverlay else {
167+ return
168+ }
150169 UIView . animate ( withDuration: 0.3 ) {
151- self . grid . alpha = 0
170+ itemOverlay . alpha = 0
152171 }
153172 }
154173}
@@ -166,16 +185,19 @@ extension YPAssetViewContainer: UIGestureRecognizerDelegate {
166185
167186 @objc
168187 private func handleTouchDown( sender: UILongPressGestureRecognizer ) {
188+ guard let itemOverlay = itemOverlay else {
189+ return
190+ }
169191 switch sender. state {
170192 case . began:
171193 if isShown {
172194 UIView . animate ( withDuration: 0.1 ) {
173- self . grid . alpha = 1
195+ itemOverlay . alpha = 1
174196 }
175197 }
176198 case . ended:
177199 UIView . animate ( withDuration: 0.3 ) {
178- self . grid . alpha = 0
200+ itemOverlay . alpha = 0
179201 }
180202 default : ( )
181203 }
0 commit comments