在我的項目中,我使用的是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