From 8ba3e450b07f12dd3c7a8191e786b6f7f825952a Mon Sep 17 00:00:00 2001 From: Bartosz Kryza Date: Wed, 26 Mar 2014 18:27:28 +0100 Subject: [PATCH] Added copying of cell's layer properties (cornerRadius, borderWidth, etc.) to the draggable preview --- .../LXReorderableCollectionViewFlowLayout.m | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m b/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m index e975dd7..4e8dca7 100755 --- a/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m +++ b/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m @@ -287,18 +287,51 @@ - (void)handleLongPressGesture:(UILongPressGestureRecognizer *)gestureRecognizer UICollectionViewCell *collectionViewCell = [self.collectionView cellForItemAtIndexPath:self.selectedItemIndexPath]; - self.currentView = [[UIView alloc] initWithFrame:collectionViewCell.frame]; + // + // Get the draggable cell preview a frame based on bounds (independent of current transform) + // and adjust the center to the cell's frame center + // + self.currentView = [[UIView alloc] initWithFrame:collectionViewCell.bounds]; + self.currentView.center = collectionViewCell.center; + collectionViewCell.highlighted = YES; UIImageView *highlightedImageView = [[UIImageView alloc] initWithImage:[collectionViewCell LX_rasterizedImage]]; highlightedImageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; highlightedImageView.alpha = 1.0f; + // Maintain the cell's layer properties in highlight preview + highlightedImageView.clipsToBounds = YES; + highlightedImageView.layer.cornerRadius = collectionViewCell.layer.cornerRadius; + highlightedImageView.layer.borderColor = collectionViewCell.layer.borderColor; + highlightedImageView.layer.borderWidth = collectionViewCell.layer.borderWidth; + + collectionViewCell.highlighted = NO; UIImageView *imageView = [[UIImageView alloc] initWithImage:[collectionViewCell LX_rasterizedImage]]; imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; imageView.alpha = 0.0f; + // Maintain the cell's layer properties in image preview + imageView.clipsToBounds = YES; + imageView.layer.cornerRadius = collectionViewCell.layer.cornerRadius; + imageView.layer.borderColor = collectionViewCell.layer.borderColor; + imageView.layer.borderWidth = collectionViewCell.layer.borderWidth; + + // + // Maintain the cell's layer border and shadow attributes + // Here we have to disable clipsToBounds in order to make the shadow visible if availble + // + self.currentView.clipsToBounds = NO; + CGFloat cornerRadius = collectionViewCell.layer.cornerRadius; + self.currentView.layer.cornerRadius = cornerRadius; + self.currentView.layer.shadowColor = collectionViewCell.layer.shadowColor; + self.currentView.layer.shadowOffset = collectionViewCell.layer.shadowOffset; + self.currentView.layer.shadowRadius = collectionViewCell.layer.shadowRadius; + self.currentView.layer.shadowOpacity = collectionViewCell.layer.shadowOpacity; + self.currentView.layer.shadowPath = collectionViewCell.layer.shadowPath; + self.currentView.backgroundColor = [UIColor clearColor]; + [self.currentView addSubview:imageView]; [self.currentView addSubview:highlightedImageView]; [self.collectionView addSubview:self.currentView];