1

カスタム セル ビューに画像を読み込むために非同期画像ビューを実装しましたが、画像がセル上で小さく表示されます。そのため、その画像ビューをクリックすると、その画像を拡大して表示する必要があります。どうすればこれを達成できますか?

これは私のコードです:

 if (cell == nil) {
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

     //create new cell
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

     //common settings
     cell.selectionStyle = UITableViewCellSelectionStyleNone;
     cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
     cell.layer.cornerRadius = 10; 
     cell.layer.masksToBounds = YES;

     cell.imageView.contentMode = UIViewContentModeScaleAspectFit;
     cell.imageView.frame = CGRectMake(10.0f, 10.0f, 60.0f, 44.0f);
     cell.imageView.backgroundColor = [UIColor colorWithRed:73 green:73 blue:73 alpha:1];

     cell.imageView.image = [UIImage imageNamed:@"Placeholder.png"];
     imgBtn=[cell imageView];
     objectAtIndex:indexPath.row]objectForKey:@"Name"];
     cell.imageView.imageURL =  [NSURL URLWithString:[[detailsList objectAtIndex:indexPath.row]objectForKey:@"image_url"]];
}

セル内の画像ビューをタッチして画像を拡大したい。何か案は?前もって感謝します。

4

4 に答える 4

3

次のように、ジェスチャ認識機能を使用して画像を追加できます。-

UITapGestureRecognizer *tapped = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageTapped:)];           
tapped.numberOfTapsRequired = 1;
[image setUserInteractionEnabled:YES];
image.tag = indexPath.row;
[image addGestureRecognizer:tapped];   
[cell.contentView addSubview:image];

そして、あなたのimagetapped関数は次のようになります:-

 - (void)imageTapped:(UITapGestureRecognizer *)gesture 
{
    UIImageView *img = (UIImageView *)[gesture view];
    BigimgView.image = img.image
    [self.view addSubview:BigimgView];
    UITableViewCell *cell = [MyTableView cellForRowAtIndexPath:[NSIndexPath indexPathWithIndex:img.tag]];

}

BigimgViewは、大きなサイズのimageviewのiboutletにすることができます。

于 2012-07-09T11:19:25.350 に答える
1

カスタムセルにボタンを追加します。

@interface custom : UITableViewCell
{
    UIButton *button1
}

次に、xibにボタンも追加します。次に、そのボタンに接続します。

tableviewデータソースメソッドに来てください。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    static NSString *CellIdentifier = @"CellIdentifier";

    // Dequeue or create a cell of the appropriate type.
    /// UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    custom *cell=(custom *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) 
    {
        // cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        NSArray *topView=[[NSBundle mainBundle]loadNibNamed:@"custom" owner:self options:nil];

        for(id currentobject in topView)
        {
            if ([currentobject isKindOfClass:[UITableViewCell class]])
            {
                cell=(custom *)currentobject;
                //cell.backgroundView.backgroundColor=[UIColor clearColor];

                 break;
             }
         }
    }   
    //  0.0f, 0.0f , cell.imageView.frame.size.width,        cell.imageView.frame.size.height
    [cell.button1 addTarget:self action:@selector(changeSize) forControlEvents:UIControlEventTouchUpInside];
}

ボタンをクリックしてください。そのメソッドに移動します.,.,試してみてください.,.,

-(IBAction)changeSize:(UIButton *)sender
{
    UIImageView * imageView = (UIImageView *)[sender superview];
    imageView.frame = //Your larger frame goes here
}

cell.button1 の背景画像を指定する必要があります。

私は学んでいます。、

于 2012-07-09T12:11:36.063 に答える
1

imageViewをタップしたときにメッセージを受け取りたいですか?考えられる解決策は、おそらく独自の xib ファイルで、カスタム UITableViewCell を作成することです。

次に、カスタム UITableViewCell の UIImageView をクリック可能にすることが問題になります。この質問を見てください:こちら

より簡単な解決策は、UIImageView ではなく UIButton を使用することです。image/backgroundImage を UIButton に設定できます。

于 2012-07-09T11:23:01.447 に答える
1

UIButton を使用してみてください:

UIButton * b = [[UIButton alloc] initWithFrame:CGRectMake(0.0f, 0.0f , cell.imageView.frame.size.width, cell.imageView.frame.size.height)];
b.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[b addTarget:self action:@selector(changeSize:) forControlEvents:UIControlEventTouchUpInside];
[cell.imageView addSubview:b];

-(IBAction)changeSize:(UIButton *)sender
{
    UIImageView * imageView = (UIImageView *)[sender superview];
    imageView.frame = //Your larger frame goes here
}
于 2012-07-09T11:27:11.953 に答える