在您的视图中放大图片

时间:2013-03-04 07:08:10

标签: objective-c uitableview

我有一个表格视图,当我选择任何一行时,它会显示该特定项目的详细信息。细节包含该项目的图片。现在我想点击它后放大图片。请帮忙,因为我是这个iOS领域的新手。

contentview = [[UIImageView alloc]init];
    [contentview setFrame:CGRectMake(10, 10, 300, 150)];
    [contentview setImage:[UIImage imageNamed:@"chicken tikka.png"]];
    [self.view addSubview: contentview];
    [contentview release];

    UIWebView *ingradients= [[UIWebView alloc]init];
    [ingradients setFrame:CGRectMake(10, 170, 300, 300)];
[ingradients loadHTMLString:@"<html><body><p style:color:red><strong>INGREDIENTS</strong></p><ul><li>One kg Chicken</li><li>Half kg Onion</li><li>200gm Tomato</li></ul></body></html>" baseURL:nil];

    ingradients.delegate=self;
    [self.view addSubview:ingradients];

1 个答案:

答案 0 :(得分:2)

我认为此代码对您有所帮助

        imageScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, screenRect.size.width, screenRect.size.height)];
        imageScrollView.maximumZoomScale = 2.50;
        imageScrollView.minimumZoomScale = 1.00;
        imageScrollView.clipsToBounds = YES;
        imageScrollView.delegate = self;
        [self.view addSubview:imageScrollView];

        imageView_temp = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, screenRect.size.width, screenRect.size.height)];
        imageView_temp.contentMode = UIViewContentModeScaleToFill;
        imageView_temp.backgroundColor = [UIColor clearColor];
        [imageView_temp setUserInteractionEnabled:YES];
        originalImagePos = imageView_temp.center;
        [imageScrollView addSubview:imageView_temp];

        // scrollview content size
        imageScrollView.contentSize = CGSizeMake(imageView_temp.frame.size.width, imageView_temp.frame.size.height);

// call this method for to zoom in
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {

    return imageView_temp;
}

// call this method for to zoom out
-(void)resetImageZoom {

    NSLog(@"Resetting any image zoom");

    CGAffineTransform transform = CGAffineTransformMakeScale(1.0, 1.0);

    imageView_temp.transform = transform;

    [imageScrollView setContentSize:CGSizeZero];

    imageView_temp.center = originalImagePos;
}