Skip to content

Commit 3c955a7

Browse files
committed
[Issue lxcid#49] Replaces LX_rasterizedImage with LX_snapshotView which attempts to use the iOS 7 snapshot function whenever possible.
1 parent b47d5a7 commit 3c955a7

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,22 @@ - (NSDictionary *) LX_userInfo {
4545

4646
@interface UICollectionViewCell (LXReorderableCollectionViewFlowLayout)
4747

48-
- (UIImage *)LX_rasterizedImage;
48+
- (UIView *)LX_snapshotView;
4949

5050
@end
5151

5252
@implementation UICollectionViewCell (LXReorderableCollectionViewFlowLayout)
5353

54-
- (UIImage *)LX_rasterizedImage {
55-
UIGraphicsBeginImageContextWithOptions(self.bounds.size, self.isOpaque, 0.0f);
56-
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
57-
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
58-
UIGraphicsEndImageContext();
59-
return image;
54+
- (UIView *)LX_snapshotView {
55+
if ([self respondsToSelector:@selector(snapshotViewAfterScreenUpdates:)]) {
56+
return [self snapshotViewAfterScreenUpdates:YES];
57+
} else {
58+
UIGraphicsBeginImageContextWithOptions(self.bounds.size, self.isOpaque, 0.0f);
59+
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
60+
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
61+
UIGraphicsEndImageContext();
62+
return [[UIImageView alloc] initWithImage:image];
63+
}
6064
}
6165

6266
@end
@@ -290,12 +294,12 @@ - (void)handleLongPressGesture:(UILongPressGestureRecognizer *)gestureRecognizer
290294
self.currentView = [[UIView alloc] initWithFrame:collectionViewCell.frame];
291295

292296
collectionViewCell.highlighted = YES;
293-
UIImageView *highlightedImageView = [[UIImageView alloc] initWithImage:[collectionViewCell LX_rasterizedImage]];
297+
UIView *highlightedImageView = [collectionViewCell LX_snapshotView];
294298
highlightedImageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
295299
highlightedImageView.alpha = 1.0f;
296300

297301
collectionViewCell.highlighted = NO;
298-
UIImageView *imageView = [[UIImageView alloc] initWithImage:[collectionViewCell LX_rasterizedImage]];
302+
UIView *imageView = [collectionViewCell LX_snapshotView];
299303
imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
300304
imageView.alpha = 0.0f;
301305

0 commit comments

Comments
 (0)