UIScrollView根本用法和代理方法
UIScrollView基本用法和代理方法
UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(50, 0, 200, 400)];
// 内容的高和宽(滚动区间的大小左右)
scrollView.contentSize = CGSizeMake(400, 400);
// scrollView.contentOffset = CGPointMake(20, 20);
// 设置区间的大小(上,下,左,右);
// UIEdgeInsets edgeInsert = {10,10,10,10};
// scrollView.contentInset = edgeInsert;
scrollView.backgroundColor = [UIColor blueColor];
scrollView.pagingEnabled = YES;
UILabel *laber1 = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 400)];
laber1.backgroundColor = [UIColor brownColor];
[scrollView addSubview:laber1];
[laber1 release];
UILabel *laber2 = [[UILabel alloc]initWithFrame:CGRectMake(200, 0, 100, 400)];
laber2.backgroundColor = [UIColor yellowColor];
[scrollView addSubview:laber2];
[laber2 release];
// 放大的最大倍数
scrollView.maximumZoomScale = 2.0;
// 放大的最小倍数
scrollView.minimumZoomScale = 0.5;
// 手指放开后的速率
scrollView.decelerationRate = 1;
// 设置是否有滚动条
scrollView.showsHorizontalScrollIndicator = YES;
scrollView.delegate = self;
// yes移动手指足够长的长度触发事件,
scrollView.canCancelContentTouches = NO;
[scrollView flashScrollIndicators];
// 是否同时运动,lock
scrollView.directionalLockEnabled = YES;
// 用户出发后要延迟一定的时间
scrollView.delaysContentTouches = YES;
[self addSubview:scrollView];
[scrollView release];
UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(50, 0, 200, 400)];
// 内容的高和宽(滚动区间的大小左右)
scrollView.contentSize = CGSizeMake(400, 400);
// scrollView.contentOffset = CGPointMake(20, 20);
// 设置区间的大小(上,下,左,右);
// UIEdgeInsets edgeInsert = {10,10,10,10};
// scrollView.contentInset = edgeInsert;
scrollView.backgroundColor = [UIColor blueColor];
scrollView.pagingEnabled = YES;
UILabel *laber1 = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 400)];
laber1.backgroundColor = [UIColor brownColor];
[scrollView addSubview:laber1];
[laber1 release];
UILabel *laber2 = [[UILabel alloc]initWithFrame:CGRectMake(200, 0, 100, 400)];
laber2.backgroundColor = [UIColor yellowColor];
[scrollView addSubview:laber2];
[laber2 release];
// 放大的最大倍数
scrollView.maximumZoomScale = 2.0;
// 放大的最小倍数
scrollView.minimumZoomScale = 0.5;
// 手指放开后的速率
scrollView.decelerationRate = 1;
// 设置是否有滚动条
scrollView.showsHorizontalScrollIndicator = YES;
scrollView.delegate = self;
// yes移动手指足够长的长度触发事件,
scrollView.canCancelContentTouches = NO;
[scrollView flashScrollIndicators];
// 是否同时运动,lock
scrollView.directionalLockEnabled = YES;
// 用户出发后要延迟一定的时间
scrollView.delaysContentTouches = YES;
[self addSubview:scrollView];
[scrollView release];
- (
void
)viewDidLoad
002 |
{ |
003 |
[super viewDidLoad];
|
004 |
|
005 |
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
|
006 |
scrollView.backgroundColor = [UIColor redColor];
|
007 |
// 是否支持滑动最顶端
|
008 |
// scrollView.scrollsToTop = NO; |
009 |
scrollView.delegate = self;
|
010 |
// 设置内容大小
|
011 |
scrollView.contentSize = CGSizeMake(320, 460*10);
|
012 |
// 是否反弹
|
013 |
// scrollView.bounces = NO; |
014 |
// 是否分页
|
015 |
// scrollView.pagingEnabled = YES; |
016 |
// 是否滚动
|
017 |
// scrollView.scrollEnabled = NO; |
018 |
// scrollView.showsHorizontalScrollIndicator = NO; |
019 |
// 设置indicator风格
|
020 |
// scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite; |
021 |
// 设置内容的边缘和Indicators边缘
|
022 |
// scrollView.contentInset = UIEdgeInsetsMake(0, 50, 50, 0); |
023 |
// scrollView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 50, 0, 0); |
024 |
// 提示用户,Indicators flash
|
025 |
[scrollView flashScrollIndicators];
|
026 |
// 是否同时运动,lock
|
027 |
scrollView.directionalLockEnabled = YES;
|
028 |
[self.view addSubview:scrollView];
|
029 |
|
030 |
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 200, 320, 40)];
|
031 |
label.backgroundColor = [UIColor yellowColor];
|
032 |
label.text = @ "学习scrolleview" ;
|
033 |
[scrollView addSubview:label];
|
034 |
[label release];
|
035 |
} |
#pragma mark -
038 |
/* |
039 |
// 返回一个放大或者缩小的视图 |
040 |
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView |
041 |
{ |
042 |
|
043 |
} |
044 |
// 开始放大或者缩小 |
045 |
- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView: |
046 |
(UIView *)view |
047 |
{ |
048 |
|
049 |
} |
050 |
051 |
// 缩放结束时 |
052 |
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale |
053 |
{ |
054 |
|
055 |
} |
056 |
|
057 |
// 视图已经放大或缩小 |
058 |
- (void)scrollViewDidZoom:(UIScrollView *)scrollView |
059 |
{ |
060 |
NSLog(@"scrollViewDidScrollToTop"); |
061 |
} |
062 |
*/
|
063 |
064 |
// 是否支持滑动至顶部 |
065 |
- ( BOOL )scrollViewShouldScrollToTop:(UIScrollView *)scrollView
|
066 |
{ |
067 |
return
YES;
|
068 |
} |
069 |
070 |
// 滑动到顶部时调用该方法 |
071 |
- ( void )scrollViewDidScrollToTop:(UIScrollView *)scrollView
|
072 |
{ |
073 |
NSLog(@ "scrollViewDidScrollToTop" );
|
074 |
} |
075 |
076 |
// scrollView 已经滑动 |
077 |
- ( void )scrollViewDidScroll:(UIScrollView *)scrollView
|
078 |
{ |
079 |
NSLog(@ "scrollViewDidScroll" );
|
080 |
} |
081 |
082 |
// scrollView 开始拖动 |
083 |
- ( void )scrollViewWillBeginDragging:(UIScrollView *)scrollView
|
084 |
{ |
085 |
NSLog(@ "scrollViewWillBeginDragging" );
|
086 |
} |
087 |
088 |
// scrollView 结束拖动 |
089 |
- ( void )scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:( BOOL )decelerate
|
090 |
{ |
091 |
NSLog(@ "scrollViewDidEndDragging" );
|
092 |
} |
093 |
094 |
// scrollView 开始减速(以下两个方法注意与以上两个方法加以区别) |
095 |
- ( void )scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
|
096 |
{ |
097 |
NSLog(@ "scrollViewWillBeginDecelerating" );
|
098 |
} |
099 |
100 |
// scrollview 减速停止 |
101 |
- ( void )scrollViewDidEndDecelerating:(UIScrollView *)scrollView
|
102 |
{ |
103 |
NSLog(@ "scrollViewDidEndDecelerating" );
|
104 |
} |