77//
88
99import Foundation
10- import TLPhotoPicker
1110import PhotosUI
11+ import TLPhotoPicker
1212
1313class Cell : TLPhotoCollectionViewCell {
14-
15- var configure = MultipleImagePickerConfigure
16-
14+ static let longPressNotification = Notification . Name ( " CellLongPressNotification " )
15+
16+ // Khởi tạo cell và thiết lập sự kiện Long Press
17+ override init ( frame: CGRect ) {
18+ super. init ( frame: frame)
19+ self . setupLongPressGesture ( )
20+ }
21+
22+ required init ? ( coder aDecoder: NSCoder ) {
23+ super. init ( coder: aDecoder)
24+ self . setupLongPressGesture ( )
25+ }
26+
27+ private func setupLongPressGesture( ) {
28+ let longPressGesture = UILongPressGestureRecognizer ( target: self , action: #selector( self . handleLongPress ( _: ) ) )
29+ addGestureRecognizer ( longPressGesture)
30+ }
31+
32+ // Xử lý sự kiện Long Press
33+ @objc private func handleLongPress( _ gestureRecognizer: UILongPressGestureRecognizer ) {
34+ guard gestureRecognizer. state == . began && !self . isCameraCell
35+ else {
36+ return
37+ }
38+
39+ NotificationCenter . default. post ( name: Cell . longPressNotification, object: self )
40+ }
41+
42+ private func findViewController( ) -> UIViewController ? {
43+ var responder : UIResponder ? = self
44+ while let currentResponder = responder {
45+ if let viewController = currentResponder as? UIViewController {
46+ return viewController
47+ }
48+ responder = currentResponder. next
49+ }
50+ return nil
51+ }
52+
1753 override var duration : TimeInterval ? {
1854 didSet {
1955 self . durationLabel? . isHidden = self . duration == nil ? true : false
2056 guard let duration = self . duration else { return }
2157 self . durationLabel? . text = timeFormatted ( timeInterval: duration)
2258 }
2359 }
24-
60+
2561 override var isCameraCell : Bool {
2662 didSet {
2763 self . orderLabel? . isHidden = self . isCameraCell
@@ -31,7 +67,7 @@ class Cell: TLPhotoCollectionViewCell {
3167
3268 override public var selectedAsset : Bool {
3369 willSet( newValue) {
34- self . orderLabel? . backgroundColor = newValue ? self . configure . selectedColor : UIColor ( red: 1 , green: 1 , blue: 1 , alpha: 0.3 )
70+ self . orderLabel? . backgroundColor = newValue ? config . selectedColor : UIColor ( red: 1 , green: 1 , blue: 1 , alpha: 0.3 )
3571 }
3672 }
3773
@@ -43,13 +79,12 @@ class Cell: TLPhotoCollectionViewCell {
4379 self . orderLabel? . layer. cornerRadius = 12
4480 self . orderLabel? . layer. borderWidth = 2
4581 self . orderLabel? . layer. borderColor = UIColor . white. cgColor
46- self . videoIconImageView? . image = self . configure . videoIcon
82+ self . videoIconImageView? . image = config . videoIcon
4783 if #available( iOS 11 . 0 , * ) {
4884 self . imageView? . accessibilityIgnoresInvertColors = true
4985 self . playerView? . accessibilityIgnoresInvertColors = true
5086 self . livePhotoView? . accessibilityIgnoresInvertColors = true
5187 self . videoIconImageView? . accessibilityIgnoresInvertColors = true
5288 }
5389 }
54-
5590}
0 commit comments