@@ -107,6 +107,30 @@ - (void)setupCollectionView {
107107 [[NSNotificationCenter defaultCenter ] addObserver: self selector: @selector (handleApplicationWillResignActive: ) name: UIApplicationWillResignActiveNotification object: nil ];
108108}
109109
110+ - (void )tearDownCollectionView {
111+ // Tear down long press gesture
112+ if (_longPressGestureRecognizer) {
113+ UIView *view = _longPressGestureRecognizer.view ;
114+ if (view) {
115+ [view removeGestureRecognizer: _longPressGestureRecognizer];
116+ }
117+ _longPressGestureRecognizer.delegate = nil ;
118+ _longPressGestureRecognizer = nil ;
119+ }
120+
121+ // Tear down pan gesture
122+ if (_panGestureRecognizer) {
123+ UIView *view = _panGestureRecognizer.view ;
124+ if (view) {
125+ [view removeGestureRecognizer: _panGestureRecognizer];
126+ }
127+ _panGestureRecognizer.delegate = nil ;
128+ _panGestureRecognizer = nil ;
129+ }
130+
131+ [[NSNotificationCenter defaultCenter ] removeObserver: self name: UIApplicationWillResignActiveNotification object: nil ];
132+ }
133+
110134- (id )init {
111135 self = [super init ];
112136 if (self) {
@@ -127,8 +151,8 @@ - (id)initWithCoder:(NSCoder *)aDecoder {
127151
128152- (void )dealloc {
129153 [self invalidatesScrollTimer ];
154+ [self tearDownCollectionView ];
130155 [self removeObserver: self forKeyPath: kLXCollectionViewKeyPath ];
131- [[NSNotificationCenter defaultCenter ] removeObserver: self name: UIApplicationWillResignActiveNotification object: nil ];
132156}
133157
134158- (void )applyLayoutAttributes : (UICollectionViewLayoutAttributes *)layoutAttributes {
@@ -490,6 +514,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
490514 [self setupCollectionView ];
491515 } else {
492516 [self invalidatesScrollTimer ];
517+ [self tearDownCollectionView ];
493518 }
494519 }
495520}
0 commit comments