UIViewController
에서 과 함께 표준 격자 레이아웃으로 배열 된 UICollectionView
으로 작업하고 있습니다. 사용자가 하나의 셀 (handleTap UITapGestureRecognizer
을 통해 선택)을 선택하면 다음 중 하나 또는 모두를 수행하고 싶습니다.선택한 셀을 강조 표시 또는 확대합니까?
(1) 셀을 다른 색상으로 강조/색상 지정 - 알파 및 배경색 변경 이
가(3) 나는 현재 다음과 같은 기능을 사용하고
수정 된 세포의 프레임 또는 경계 주위에 테두리를 그릴, 결코 어떤 주위
(2) 약간 다른 셀을 변경하지 않고 셀을 확대 셀이 적절히 구분되어 선택 되었음에도 불구하고 호출되며 로컬 변수 0에 저장됩니다..
-(CGSize) collectionView:(UICollectionView*)collectionView layout:(UICollectionViewFlowLayout*)layout sizeForItemAtIndexPath: (NSIndexPath*)indexPath
{
if ([indexPath isEqual:selectedCellIndexPath])
{
return CGSizeMake([MyCollectionViewCell width] + 4, [MyCollectionViewCell height] + 4);
} else {
return CGSizeMake([MyCollectionViewCell width], [MyCollectionViewCell height]);
}
}
하지만 (새로운 위치로 이동을 유발) 주위 다른 모든 세포를 방해, 내 선택된 셀 주변에 큰 버퍼를 만들어 어떤 이유로, 여기 제안 나는 또한 레이아웃을 무효화 시도했습니다
, 아직 확대 된 사용자 정의 셀 안에있는 내용 (imageView)은 확대되지 않습니다. 나는. 그것은 선택에서 실행하지만 UICollectionView: Animate cell size change on selection 여기
이 경우에도 작동하지 않았다 더 많은 샘플 코드 : 그 안에 이미지 뷰 내가 특별히뿐만 아니라 imageView.frame 및 imageView.image의 크기를 변화에도 불구하고, 같은 크기를 유지 셀 :
-(void) collectionView:(UICollectionView*)collectionView didSelectItemAtIndexPath:(NSIndexPath*)indexPath
{
NSLog(@"Cell Selected!");
MyCollectionViewCell* cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"StorageCell" forIndexPath:indexPath];
MyImageView* selectedCellView = cell.imgView;
MyCollectionViewFlowLayout* layout = (MyCollectionViewFlowLayout*)self.collection.collectionViewLayout;
layout.currentCellPath = indexPath;
layout.currentCellCenter = selectedCellView.center;
layout.currentCellScale = 1.25;
[self.collection.collectionViewLayout invalidateLayout];
// Animate
[UIView transitionWithView:cell duration:0.1f options: UIViewAnimationOptionCurveLinear animations:^(void)
{
CGRect frame = cell.frame;
frame.size = CGSizeMake(60.0, 100.0);
cell.frame = frame;
selectedCellView.imgView.image = [UIImage imageNamed:@"wood2.png"];
[self.collection reloadItemsAtIndexPaths:@[indexPath]];
NSLog(@"Cell Frame animated to: %f,%f", cell.frame.size.width, cell.frame.size.height);
frame = selectedCellView.frame;
frame.size.width = 1.25*frame.size.width;
frame.size.height = 1.25*frame.size.height;
selectedCellView.frame = frame;
frame = selectedCellView.imgView.frame;
frame.size.width = 1.25*frame.size.width;
frame.size.height = 1.25*frame.size.height;
selectedCellView.imgView.frame = frame;
UICollectionViewLayoutAttributes* attrib = [collection layoutAttributesForItemAtIndexPath:indexPath];
attrib.transform3D = CATransform3DMakeScale(2, 2, 1.0);
selectedCellView.imgView.frame.transform = CGAffineTransformScale(selectedCellView.imgView.transform, 1.1, 1.1);
}
completion:nil];
}
감사합니다. 확대를 취소하려면 선택 취소 방법에서 아무 것도해야합니까? – Cindeselia
예, 비슷한 방법을 구현하고 변환을 'CGAffineTransformMakeScale (1,1)'로 설정하면 되돌릴 수 있습니다. – NavinDev