必须至少有三个步骤:
一,实现协议
二,建立关系
三,设置缩放的范围
具体见代码:
#import "ViewController.h" @interface ViewController () <UIScrollViewDelegate> //一定要先遵守这个协议 @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
时间: 2024-11-10 07:02:45