GridView的照片和缩放点击任何图像
我希望创建一个网格状的照片库,其中每行有3张照片,具有相同的帧大小。当用户点击任何照片时,它必须按照所附图像中的给定进行缩放&其他照片必须相应地对齐 我不熟悉UICollectionView。但是,我已经成功地在一行中显示了3个单元格,如下面的屏幕截图所示 我所做的类似于UITableview的显示。我创建了一个新的UICollectionviewCell类,其中声明了单个单元格的框架 bigBoxIndex是必须在其中展开单元格的indexpath.rowGridView的照片和缩放点击任何图像,grid,uicollectionview,gallery,uicollectionviewcell,image-gallery,Grid,Uicollectionview,Gallery,Uicollectionviewcell,Image Gallery,我希望创建一个网格状的照片库,其中每行有3张照片,具有相同的帧大小。当用户点击任何照片时,它必须按照所附图像中的给定进行缩放&其他照片必须相应地对齐 我不熟悉UICollectionView。但是,我已经成功地在一行中显示了3个单元格,如下面的屏幕截图所示 我所做的类似于UITableview的显示。我创建了一个新的UICollectionviewCell类,其中声明了单个单元格的框架 bigBoxIndex是必须在其中展开单元格的indexpath.row - (CGSize)collect
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
if (bigBoxIndex == indexPath.row) {
return CGSizeMake(bigBoxWidth, bigBoxHeight);
}
else {
return CGSizeMake(boxWidth, boxHeight);
}
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
DealListCVCell *cell = (DealListCVCell*)[collectionView cellForItemAtIndexPath:indexPath];
DealListCVCell *expandedCell = (DealListCVCell*)[collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForRow:bigBoxIndex inSection:0]];
if (bigBoxIndex == indexPath.row) {
bigBoxIndex = -1;
}
else {
bigBoxIndex = indexPath.row;
}
if (bigBoxIndex == -1) {
[collectionView performBatchUpdates:^{
for (NSInteger i = 0; i < NUMBER_OF_ITEMS; i++) {
NSIndexPath *fromIndexPath = [NSIndexPath indexPathForRow:i inSection:0];
NSInteger j = i;
NSIndexPath *toIndexPath = [NSIndexPath indexPathForRow:j inSection:0];
[collectionView moveItemAtIndexPath:fromIndexPath toIndexPath:toIndexPath];
}
} completion:^(BOOL finished) {}];
[UIView beginAnimations:@"Zoom" context:NULL];
[UIView setAnimationDuration:0.3];
[expandedCell.dealImg setFrame:CGRectMake(2.0f, 2.0f, boxWidth-4.0f, boxHeight-4.0f)];
[UIView commitAnimations];
}
else {
[UIView beginAnimations:@"Zoom" context:NULL];
[UIView setAnimationDuration:0.3];
[cell.dealImg setFrame:CGRectMake(2.0f, 2.0f, (2 * boxWidth)-4.0f, (2 * boxHeight)-4.0f)];
[UIView commitAnimations];
[collectionView performBatchUpdates:^{
[expandedCell.dealImg setFrame:CGRectMake(2.0f, 2.0f, boxWidth-4.0f, boxHeight-4.0f)];
for (NSInteger i = 0; i < [[self.entries objectAtIndex:0] count]; i++) {
NSIndexPath *fromIndexPath = [NSIndexPath indexPathForRow:i inSection:0];
NSInteger j = i;
NSIndexPath *toIndexPath = [NSIndexPath indexPathForRow:j inSection:0];
[collectionView moveItemAtIndexPath:fromIndexPath toIndexPath:toIndexPath];
}
} completion:^(BOOL finished) {}];
}
}
根据我的代码,当用户点击图像时,图像会放大,如下面的截图所示
如何管理单行的布局