@@ -142,9 +142,13 @@ - (void)invalidateLayoutIfNecessary {
142142
143143 [self .dataSource collectionView: self .collectionView itemAtIndexPath: previousIndexPath willMoveToIndexPath: newIndexPath];
144144
145+ __weak typeof (self) weakSelf = self;
145146 [self .collectionView performBatchUpdates: ^{
146- [self .collectionView deleteItemsAtIndexPaths: @[ previousIndexPath ]];
147- [self .collectionView insertItemsAtIndexPaths: @[ newIndexPath ]];
147+ __strong typeof (self) strongSelf = weakSelf;
148+ if (strongSelf) {
149+ [strongSelf.collectionView deleteItemsAtIndexPaths: @[ previousIndexPath ]];
150+ [strongSelf.collectionView insertItemsAtIndexPaths: @[ newIndexPath ]];
151+ }
148152 } completion: nil ];
149153}
150154
@@ -274,20 +278,27 @@ - (void)handleLongPressGesture:(UILongPressGestureRecognizer *)gestureRecognizer
274278
275279 self.currentViewCenter = self.currentView .center ;
276280
281+ __weak typeof (self) weakSelf = self;
277282 [UIView
278283 animateWithDuration: 0.3
279284 delay: 0.0
280285 options: UIViewAnimationOptionBeginFromCurrentState
281286 animations: ^{
282- self.currentView .transform = CGAffineTransformMakeScale (1 .1f , 1 .1f );
283- highlightedImageView.alpha = 0 .0f ;
284- imageView.alpha = 1 .0f ;
287+ __strong typeof (self) strongSelf = weakSelf;
288+ if (strongSelf) {
289+ strongSelf.currentView .transform = CGAffineTransformMakeScale (1 .1f , 1 .1f );
290+ highlightedImageView.alpha = 0 .0f ;
291+ imageView.alpha = 1 .0f ;
292+ }
285293 }
286294 completion: ^(BOOL finished) {
287- [highlightedImageView removeFromSuperview ];
288-
289- if ([self .delegate respondsToSelector: @selector (collectionView:didBeginDraggingItemAtIndexPath: )]) {
290- [self .delegate collectionView: self .collectionView didBeginDraggingItemAtIndexPath: self .selectedItemIndexPath];
295+ __strong typeof (self) strongSelf = weakSelf;
296+ if (strongSelf) {
297+ [highlightedImageView removeFromSuperview ];
298+
299+ if ([strongSelf.delegate respondsToSelector: @selector (collectionView:didBeginDraggingItemAtIndexPath: )]) {
300+ [strongSelf.delegate collectionView: strongSelf.collectionView didBeginDraggingItemAtIndexPath: strongSelf.selectedItemIndexPath];
301+ }
291302 }
292303 }];
293304
@@ -306,21 +317,28 @@ - (void)handleLongPressGesture:(UILongPressGestureRecognizer *)gestureRecognizer
306317
307318 UICollectionViewLayoutAttributes *layoutAttributes = [self layoutAttributesForItemAtIndexPath: currentIndexPath];
308319
320+ __weak typeof (self) weakSelf = self;
309321 [UIView
310322 animateWithDuration: 0.3
311323 delay: 0.0
312324 options: UIViewAnimationOptionBeginFromCurrentState
313325 animations: ^{
314- self.currentView .transform = CGAffineTransformMakeScale (1 .0f , 1 .0f );
315- self.currentView .center = layoutAttributes.center ;
326+ __strong typeof (self) strongSelf = weakSelf;
327+ if (strongSelf) {
328+ strongSelf.currentView .transform = CGAffineTransformMakeScale (1 .0f , 1 .0f );
329+ strongSelf.currentView .center = layoutAttributes.center ;
330+ }
316331 }
317332 completion: ^(BOOL finished) {
318- [self .currentView removeFromSuperview ];
319- self.currentView = nil ;
320- [self invalidateLayout ];
321-
322- if ([self .delegate respondsToSelector: @selector (collectionView:didEndDraggingItemAtIndexPath: )]) {
323- [self .delegate collectionView: self .collectionView didEndDraggingItemAtIndexPath: currentIndexPath];
333+ __strong typeof (self) strongSelf = weakSelf;
334+ if (strongSelf) {
335+ [strongSelf.currentView removeFromSuperview ];
336+ strongSelf.currentView = nil ;
337+ [strongSelf invalidateLayout ];
338+
339+ if ([strongSelf.delegate respondsToSelector: @selector (collectionView:didEndDraggingItemAtIndexPath: )]) {
340+ [strongSelf.delegate collectionView: strongSelf.collectionView didEndDraggingItemAtIndexPath: currentIndexPath];
341+ }
324342 }
325343 }];
326344 }
0 commit comments