UIScrollView的基本用法

weixin_33751566發表於2016-09-10

//初始化UIScrollView    

UIScrollView *sc = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];   

 sc.backgroundColor = [UIColor orangeColor];UIImage *image = [UIImage imageNamed:@"death"];   

 UIImageView *iv = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, image.size.width, image.size.height)];    

iv.image = image;        

//滾動範圍: contentSize --> 要比scrollView的size大    

//滾動範圍一定要比scrollcview的本身大   

 sc.contentSize = image.size;       

 //偏移量:  contentOffset --> 滾動到某一個位置(點)

//    sc.contentOffset = CGPointMake(self.view.frame.size.width, 0);        

//bounces - 彈簧效果

//    sc.bounces = NO;        

/**    

 alwaysBounceVertical - 一定會出現彈簧效果 - 縱向    

 alwaysBounceHorizontal - 橫向    */    

sc.alwaysBounceVertical = YES;    

sc.alwaysBounceHorizontal = NO;            

//關閉或者開啟滾動提示器   

 //showsVeVrticalScrollIndicator  - 縱向    

//showsHorizontalScrollIndicator - 橫向   

 sc.showsVerticalScrollIndicator = NO;    

sc.showsHorizontalScrollIndicator = NO;            

//是否進行滾動

//    sc.scrollEnabled = NO;    

//設定代理:

@interface ViewController ()<UIScrollViewDelegate>

sc.delegate = self;

//1.SCrollView的放大縮小設定

//min  - 最小

//max  - 最大

//scale 放大縮小倍數 , 預設是1

sc.minimumZoomScale = 0.3;

sc.maximumZoomScale = 3;

// 返回一個放大或者縮小的檢視

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{    }

// 開始放大或者縮小

- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view{    }

// 縮放結束時

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale{    }

// 檢視已經放大或縮小

- (void)scrollViewDidZoom:(UIScrollView *)scrollView{NSLog(@"scrollViewDidScrollToTop");} */

// 是否支援滑動至頂部

- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView{    return YES;}

// 滑動到頂部時呼叫該方法

- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView{    NSLog(@"scrollViewDidScrollToTop");}

// scrollView 已經滑動

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{    NSLog(@"scrollViewDidScroll");}

// scrollView 開始拖動

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{    NSLog(@"scrollViewWillBeginDragging");}

// scrollView 結束拖動

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{    NSLog(@"scrollViewDidEndDragging");}

// scrollView 開始減速(以下兩個方法注意與以上兩個方法加以區別)

- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{    NSLog(@"scrollViewWillBeginDecelerating");}

// scrollview 減速停止

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{  NSLog(@"scrollViewDidEndDecelerating"); }

相關文章