【发布时间】:2015-10-07 06:30:03
【问题描述】:
在我的项目中,我使用UICollectionView 来显示图像,我还在UICollectionViewCell 中使用UIImageView。
我想要的只是当我点击一个应该展开并全屏显示的图像时。
为此,我创建了一个新视图,在其上使用 UIImageView,并在 UICollectionViewCells 上应用 TapGesture。
展开的图像在下一个视图中打开,但未显示在我给它的框架中。
并且当我点击它从收藏视图中删除的任何图片时。请告诉我如何重新加载UICollectionViewCells
请建议我如何将图像放在规定的框架上。
我正在分享我的代码
- (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出现了吗?框架错了吗?
-
现在添加一些快照。现在你有声望了。
-
imageview 框架设置不正确,现在我设置它并且工作正常。但问题是当我点击它从收藏视图中删除的任何图片时。请告诉我如何重新加载 uicollectionview 单元格
-
@yankitPatel 我现在添加我的截图检查它
标签: ios objective-c uiimageview uicollectionview uicollectionviewcell