我目前有一个UICollectionView
由图像网格组成的。我想要做的是,当我单击任何特定图像时,它应该打开一个图像视图,我可以在它周围平移。
问题:
- 图像视图不会显示图像。
- 如果我为图像视图启用平移,整个网格视图将移动。
我该如何避免这些问题?
这是我尝试过的:
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor=[UIColor whiteColor];
[self.collectionView registerNib:[UINib nibWithNibName:@"Cell" bundle:nil] forCellWithReuseIdentifier:@"CellID"];
// Do any additional setup after loading the view, typically from a nib.
}
-(int)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return 30;
}
-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
Cell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"CellID" forIndexPath:indexPath];
cell.backgroundColor=[UIColor whiteColor];
UIImageView *imgView=(UIImageView *)[cell viewWithTag:1];
imgView.image=[UIImage imageNamed:@"57.png"];
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
UIImageView *previewImage=[[UIImageView alloc]init];
UIScrollView *imageScroll=[[UIScrollView alloc]init];
imageScroll.clipsToBounds=YES;
imageScroll.contentSize=previewImage.bounds.size;
UIViewController *imageController=[[UIViewController alloc]init];
imageController.view.backgroundColor=[UIColor whiteColor];
[imageController.view addSubview:imageScroll];
imageController.modalPresentationStyle=UIModalTransitionStyleCrossDissolve;
imageController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:imageController animated:YES completion:^{
}];
}
任何指针?