首页 > 代码库 > UIScrollView
UIScrollView
#import "QYViewController.h"
@interface QYViewController ()<UIScrollViewDelegate>
{
UIImageView *_imageView;
}
@end
@implementation QYViewController
- (void)viewDidLoad
{
[superviewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//1.添加UIScrollerView
UIScrollView *scrollView = [[UIScrollViewalloc]init];
scrollView.frame =self.view.bounds;
//把scrollView添加到视图
[self.viewaddSubview:scrollView];
//2.添加图片
UIImage *image = [UIImageimageNamed:@"4"];
_imageView = [[UIImageViewalloc]initWithImage:image];
//设置代理
scrollView.delegate =self;
//设置最小伸缩比例
scrollView.minimumZoomScale = 0.2;
//设置最大伸缩比例
scrollView.maximumZoomScale = 2.0;
//3.设置内容范围
scrollView.contentSize = image.size;
//将_imageView添加到scrollView视图
[scrollView addSubview:_imageView];
}
#pragma mark - 这个方法返回的控件就能进行捏合手势缩放操作
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return_imageView;
}
UIScrollView