【ios控件】UIScrollView 事件说明

  1 //

  2 //  UIDemoViewController.m

  3 //  06-1UIScrollDemo

  4 //

  5 //  Created by k on 14-9-4.

  6 //  Copyright (c) 2014年 com.akleee.www. All rights reserved.

  7 //

  8 

  9 #import "UIDemoViewController.h"

 10 

 11 @interface UIDemoViewController ()<UIScrollViewDelegate>

 12 @property (weak, nonatomic) IBOutlet UIScrollView *scrollViw;

 13 @property (weak, nonatomic) IBOutlet UIImageView *img;

 14 

 15 - (IBAction)changeOffset:(id)sender;

 16 

 17 

 18 @end

 19 

 20 @implementation UIDemoViewController

 21 

 22 - (void)viewDidLoad

 23 {

 24     [super viewDidLoad];

 25     // Do any additional setup after loading the view, typically from a nib.

 26     //NSLog(@"%@",NSStringFromCGRect(_img.frame));

 27     

 28     //设置可移动区域

 29     _scrollViw.contentSize=_img.bounds.size;

 30     

 31     //可视窗口位置

 32     int moveTop=100,moveLeft=100;

 33     

 34     _scrollViw.contentOffset=CGPointMake(moveTop, moveLeft);

 35     

 36     //可视窗口大小

 37    //int windowW=100,windowH=400,windowX=10,windowY=20;

 38    // _scrollViw.frame=CGRectMake(windowX, windowY, windowW, windowH);

 39     

 40     //外边距

 41     int paddingT=10,paddingL=10,paddingR=20,paddingB=20;

 42     

 43     _scrollViw.contentInset=UIEdgeInsetsMake(paddingT, paddingL, paddingB, paddingR);

 44     

 45     //水平滚动条

 46 //    _scrollViw.showsHorizontalScrollIndicator=NO;

 47 //

 48 //    //垂直滚动条

 49 //    _scrollViw.showsVerticalScrollIndicator=NO;

 50     

 51     _scrollViw.delegate=self;

 52     

 53     _scrollViw.maximumZoomScale=2;

 54     

 55     _scrollViw.minimumZoomScale=0.1;

 56     

 57 }

 58 

 59 

 60 - (void)didReceiveMemoryWarning

 61 {

 62     [super didReceiveMemoryWarning];

 63     // Dispose of any resources that can be recreated.

 64 }

 65 -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{

 66     //开始拖拽

 67     //NSLog(@"scrollViewWillBeginDragging %@",NSStringFromCGPoint(scrollView.contentOffset));

 68     

 69 }

 70 -(void)scrollViewDidScroll:(UIScrollView *)scrollView   {

 71     //正在拖拽

 72     //NSLog(@"scrollViewDidScroll %@",NSStringFromCGPoint(scrollView.contentOffset));

 73 }

 74 

 75 

 76 -(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{

 77     //拖拽结束

 78     //NSLog(@"scrollViewDidEndDragging %@",NSStringFromCGPoint(scrollView.contentOffset));

 79 }

 80 

 81 -(void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{

 82     //拖动后开始滑行

 83     //NSLog(@"scrollViewWillBeginDecelerating %@",NSStringFromCGPoint(scrollView.contentOffset));

 84 }

 85 -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{

 86 

 87     //拖动后滑行结束

 88     //NSLog(@"scrollViewDidEndDecelerating %@",NSStringFromCGPoint(scrollView.contentOffset));

 89 

 90 }

 91 -(void)scrollViewDidScrollToTop:(UIScrollView *)scrollView{

 92     //滑动到下方内容 点击系统顶部导航 自动定位到顶部时触发

 93     //NSLog(@"scrollViewDidScrollToTop %@",NSStringFromCGPoint(scrollView.contentOffset));

 94     

 95 }

 96 

 97 

 98 -(BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView{

 99     //滑动到下方内容 点击系统顶部导航

100     NSLog(@"scrollViewShouldScrollToTop %@",NSStringFromCGPoint(scrollView.contentOffset));

101     //返回是否 自动定位到顶部

102     return NO;

103 }

104 

105 -(void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView{

106     // 当触发[_scrollViw setContentOffset:CGPointMake(200, 200) animated:YES];后  触发此事件

107     //如果animated:NO的话  不会触发此事件

108     //NSLog(@"scrollViewDidEndScrollingAnimation %@",NSStringFromCGPoint(scrollView.contentOffset));

109 }

110 

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

112     //设置需要缩放的UIView

113    // NSLog(@"viewForZoomingInScrollView %@",NSStringFromCGPoint(scrollView.contentOffset));

114     

115 

116     return _img;

117 

118 }

119 

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

121     //开始缩放

122     NSLog(@"scrollViewWillBeginZooming");

123     

124 }

125 

126 -(void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale

127 {

128     //结束缩放

129     NSLog(@"scrollViewDidEndZooming");

130 

131     

132 }

133 

134 

135 

136 

137 

138 - (IBAction)changeOffset:(id)sender {

139     NSLog(@"change offset");

140     [_scrollViw setContentOffset:CGPointMake(200, 200) animated:NO];

141     //_scrollViw .contentOffset=CGPointMake(200, 200);

142 }

143 @end

 

你可能感兴趣的:(uiscrollview)