gpt4 book ai didi

ios - 在 UICollectionView 中点击时如何将图像展开为完整 View ?

转载 作者:可可西里 更新时间:2023-11-01 05:40:32 24 4
gpt4 key购买 nike

在我的项目中,我使用 UICollectionView 来显示图像,我也在 UICollectionViewCell 中使用 UIImageView。我想要的只是当我点击一张图片时它应该展开并全屏显示。为此,我创建了一个新 View ,上面有一个 UIImageView,并在 UICollectionViewCells 上应用了 TapGesture。展开的图像在下一个 View 中打开,但没有出现在我给它的框架中。并且当我单击它从收藏 View 中删除的任何图片时。请告诉我如何重新加载 UICollectionViewCells enter image description here请建议我如何将图像放在规定的框架上。我正在分享我的代码

- (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];
}

最佳答案

所以最好在窗口中添加 View 。所以它是全屏显示。使用以下代码。

UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 50, self.view.frame.size.width , self.view.frame.size.height)];
view1.backgroundColor = [UIColor greenColor];
[self.view.window addSubview:view1];

关于ios - 在 UICollectionView 中点击时如何将图像展开为完整 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32985202/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com