利用UIScrollView实现图片的放大、缩小和移动查看

1、实现 UIScrollViewDelegate 的


- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {

    

    

    UIView *subView = [scrollView viewWithTag:22];

    return subView;

    

}




- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale {

    

    


}



两个函数;



构造相应的视图控件

UIImage *image = [UIImage imageNamed:@"1807.jpg"];

    

    

    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];

    [scrollView setContentSize:image.size];

    scrollView.delegate = self;

    scrollView.minimumZoomScale = 0.2;

    scrollView.maximumZoomScale = 5.0;

    scrollView.backgroundColor = [UIColor lightGrayColor];

    [self.view addSubview:scrollView];

    [scrollView release];

    

    

    

    

    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];

    [scrollView addSubview:imageView];

    imageView.tag = 22;

    [imageView release];






你可能感兴趣的:(iPhone开发有关)