在我的项目中,我使用的是UICollectionView
来显示图像,我也在中使用UIImageView
。 我想要的只是当我点击一张图片时,它应该展开并全屏显示。 为此,我创建了一个新视图,其上需要UIImageView
并在UICollectionViewCells
上应用TapGesture。 展开的图像在下一个视图中打开,但没有出现在我给它的框架中。 也当我点击任何图片时,它从集合视图中删除。请告诉我如何重新加载UICollectionViewCells
请建议我如何将图像放在规定的框架上。 我分享我的代码如何在UICollectionView中点击时将图像展开为完整视图?
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath];
imgview = (UIImageView *)[cell viewWithTag:100];
imgview = [[UIImageView alloc]initWithFrame:CGRectMake(0,0,160, 160)];
imgview.image = [UIImage imageNamed:[imagearray objectAtIndex:indexPath.row]];
//cell.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:[imagearray objectAtIndex:indexPath.row]]];
[cell.contentView addSubview:imgview];
UITapGestureRecognizer *tapped = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(expandImage:)];
tapped.numberOfTapsRequired = 1;
[imgview setUserInteractionEnabled:YES];
imgview.tag = indexPath.row;
[imgview addGestureRecognizer:tapped];
[cell.contentView addSubview:imgview];
return cell;
}
-(void)expandImage:(UITapGestureRecognizer*)recogniser
{
UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 50, self.view.frame.size.width , self.view.frame.size.height)];
view1.backgroundColor = [UIColor greenColor];
[self.view addSubview:view1];
UIButton *closeButton = [[UIButton alloc]initWithFrame:CGRectMake(310, 10, 50, 40)];
[closeButton setTitle:@"Close" forState:UIControlStateNormal];
[closeButton addTarget:self action:@selector(Closetab) forControlEvents:UIControlEventTouchUpInside];
[view1 addSubview:closeButton];
UIImageView *photoView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 70, self.view.frame.size.width, self.view.frame.size.height-200)];
[photoView setBackgroundColor:[UIColor blueColor]];
[view1 addSubview:photoView];
photoView.accessibilityIdentifier = @"nature2.png";
UIImageView *photoView1 = (UIImageView*)recogniser.view;
photoView1.accessibilityIdentifier = @"nature2.png";
//photoView.clipsToBounds = YES;
// photoView.accessibilityIdentifier = @"apple1.png";
photoView1.contentMode = UIViewContentModeScaleAspectFill;
//photoView1.clipsToBounds = YES;
[view1 addSubview:photoView1];
}
添加一些快照 –
我不有足够的声望(15)分数添加快照把我的问题投票了,然后我会添加它的快照 –
imageView是否出现?帧是否错误? – Aris