몇 가지 (그리고 해킹 된) 해결책을 시도한 후에, 나는 내 자신의 UICollectionView
레이아웃을 작성하여 이것을 해결했다. 이전 솔루션은 내가 시도 :
- 는 새로운 브랜드 만들지 않고 새로운 UIView의
- 을, 그것을 오버레이 배경을 흐리게하고, 애니메이션에 의해 이동 원래 셀은 셀 애니메이션
UICollectionView
와 가짜를 시도 솟다 사용자 정의에 UIView를 추가 레이아웃
나는 그것을 피하려고했지만, 코딩을 마친 후에 원래 생각했던 것보다 훨씬 덜 고통 스러웠습니다.
이
.H :이
@interface FMStackedLayout : UICollectionViewLayout
@property(nonatomic,assign) CGPoint center;
@property(nonatomic,assign) NSInteger cellCount;
-(id)initWithSelectedCellIndexPath:(NSIndexPath *)indexPath;
@end
하는 .m :
#define ITEM_WIDTH 128.0f
#define ITEM_HEIGHT 180.0f
static NSUInteger const RotationCount = 32;
static NSUInteger const RotationStride = 3;
static NSUInteger const PhotoCellBaseZIndex = 100;
@interface FMStackedLayout()
@property(strong,nonatomic) NSArray *rotations;
@property(strong,nonatomic) NSIndexPath *selectedIndexPath;
@end
@implementation FMStackedLayout
#pragma mark - Lifecycle
-(id)initWithSelectedCellIndexPath:(NSIndexPath *)indexPath{
self = [super init];
if (self) {
self.selectedIndexPath = indexPath;
[self setup];
}
return self;
}
-(id)initWithCoder:(NSCoder *)aDecoder{
self = [super init];
if (self){
[self setup];
}
return self;
}
-(void)setup{
NSMutableArray *rotations = [NSMutableArray arrayWithCapacity:RotationCount];
CGFloat percentage = 0.0f;
for (NSUInteger i = 0; i < RotationCount; i++) {
// Ensure that each angle is different enough to be seen
CGFloat newPercentage = 0.0f;
do {
newPercentage = ((CGFloat)(arc4random() % 220) - 110) * 0.0001f;
} while (fabsf(percentage - newPercentage) < 0.006);
percentage = newPercentage;
CGFloat angle = 2 * M_PI * (1.0f + percentage);
CATransform3D transform = CATransform3DMakeRotation(angle, 0.0f, 0.0f, 1.0f);
[rotations addObject:[NSValue valueWithCATransform3D:transform]];
}
self.rotations = rotations;
}
#pragma mark - Layout
-(void)prepareLayout{
[super prepareLayout];
CGSize size = self.collectionView.frame.size;
self.cellCount = [self.collectionView numberOfItemsInSection:0];
self.center = CGPointMake(size.width/2.0, size.height/2.0);
}
-(CGSize)collectionViewContentSize{
return self.collectionView.frame.size;
}
-(UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath{
UICollectionViewLayoutAttributes *attributes = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath];
attributes.size = CGSizeMake(ITEM_WIDTH, ITEM_HEIGHT);
attributes.center = self.center;
if (indexPath.item == self.selectedIndexPath.item) {
attributes.zIndex = 100;
}else{
attributes.transform3D = [self transformForPersonViewAtIndex:indexPath];
}
return attributes;
}
-(NSArray *)layoutAttributesForElementsInRect:(CGRect)rect{
NSMutableArray *attributes = [NSMutableArray array];
for (NSInteger i = 0; i < self.cellCount; i++) {
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:i
inSection:0];
[attributes addObject:[self layoutAttributesForItemAtIndexPath:indexPath]];
}
return attributes;
}
#pragma mark - Private
-(CATransform3D)transformForPersonViewAtIndex:(NSIndexPath *)indexPath{
NSInteger offset = (indexPath.section * RotationStride + indexPath.item);
return [self.rotations[offset % RotationCount] CATransform3DValue];
}
@end
그런 다음 UICollectionView에, 당신은
전화 여기
는 관심있는 사람들을 위해, 내 코드입니다
MyLayout *stackedLayout = [[MyLayout alloc] initWithSelectedCellIndexPath:indexPath];
[stackedLayout invalidateLayout];
[self.collectionView setCollectionViewLayout:stackedLayout
animated:YES];
셀 간의 애니메이션은 맞춤 레이아웃으로 처리됩니다.
이것은 답변이 아닙니다. 답을 갖고 있지만 공유에 관심이없는 것 같습니다. – Fiveagle
@ Mark Struzinski 당신의 솔루션을 공유 할 수 있습니까? –
다소 긴 코드이지만, 어떤 특별한 이유라도 가지고 있지 않습니다. 관심있는 사람을 위해 위에 게시했습니다. 왜 여기에 downvotes가 있었는지 확실하지 않습니다. 최종 해결 방법은 Apple docs : http://developer.apple.com/library/ios/#documentation/uikit/reference/UICollectionViewLayout_class/Reference/Reference.html에서 철저히 문서화 된 방법을 사용했습니다. 꽤 피곤하기 때문에 나는 그것을 피하려고 애썼다. –