必須至少有三個步驟:
一,實現協議
二,建立關系
三,設置縮放的范圍
具體見代碼:
#import "ViewController.h" @interface ViewController () //一定要先遵守這個協議 @property (weak, nonatomic) IBOutlet UIScrollView *ScrollView; @property (weak, nonatomic) IBOutlet UIImageView *minionPic; @end @implementation ViewController //滾動過程中,一直會調用該方法 - (void)scrollViewDidScroll:(UIScrollView *)scrollView { //NSLog(@"scrollViewDidScroll"); } //開始滾動時調用該方法,在拖拽一次,該方法隻調用一次且為最初開始時調用一次 -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { //NSLog(@"scrollViewWillBeginDragging"); } //當用戶開始縮放動作時代理要觸發的事件 - (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view { NSLog(@"scrollViewWillBeginZooming"); } //當用戶縮放時,要設置綻放哪個View? - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView { return self.minionPic; } - (void)viewDidLoad { [super viewDidLoad]; //設置ScrollView的內容大小contentSize self.ScrollView.contentSize= self.minionPic.frame.size; //綁定代理,建立ScrollView與代理的關系 self.ScrollView.delegate = self; //設置縮放的范圍 self.ScrollView.minimumZoomScale = 0.2; self.ScrollView.maximumZoomScale =2.0; // Do any additional setup after loading the view, typically from a nib. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end