你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> iOS UIScrollView的代理的使用及縮放時代理監聽的幾個方法

iOS UIScrollView的代理的使用及縮放時代理監聽的幾個方法

編輯:IOS開發綜合

必須至少有三個步驟:

一,實現協議

二,建立關系

三,設置縮放的范圍

具體見代碼:

 

#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


 

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved