#import "ViewController.h"
@interface ViewController ()<UIScrollViewDelegate>
@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UIScrollView *scrollView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
self.scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
self.scrollView.delegate = self;
[self.view addSubview:self.scrollView];
self.imageView = [[UIImageView alloc] initWithFrame:self.scrollView.bounds];
self.imageView.image = [UIImage imageNamed:@"1.jpg"];
[self.scrollView addSubview:self.imageView];
//scroll 的最大放大比例
self.scrollView.maximumZoomScale = 2.0;
//scroll 的最小缩小比例 必须大于零
self.scrollView.minimumZoomScale = 0.3;
}
//scroll 使用缩放功能后就不要在使用滑动功能了
//提供缩放的View,这个view必须是scrollView的子view
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
//想要缩放谁 就返回谁
return self.imageView;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
self.automaticallyAdjustsScrollViewInsets = NO; 当你的table或者ScrollView顶部留白时,设置这个属性试试