- (void)viewDidLoad
{
[super viewDidLoad];
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
scrollView.backgroundColor = [UIColor redColor];
// 是否支持滑動最頂端
//? ? scrollView.scrollsToTop = NO;
scrollView.delegate = self;
// 設置內容大小
scrollView.contentSize = CGSizeMake(320, 460*10);
// 是否反彈
//? ? scrollView.bounces = NO;
// 是否分頁
//? ? scrollView.pagingEnabled = YES;
// 是否滾動
//? ? scrollView.scrollEnabled = NO;
//? ? scrollView.showsHorizontalScrollIndicator = NO;
// 設置indicator風格
//? ? scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
// 設置內容的邊緣和Indicators邊緣
//? ? scrollView.contentInset = UIEdgeInsetsMake(0, 50, 50, 0);
//? ? scrollView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 50, 0, 0);
// 提示用戶,Indicators flash
[scrollView flashScrollIndicators];
// 是否同時運動,lock
scrollView.directionalLockEnabled = YES;
[self.view addSubview:scrollView];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 200, 320, 40)];
label.backgroundColor = [UIColor yellowColor];
label.text = @"學習scrolleview";
[scrollView addSubview:label];
[label release];
}
#pragma mark -
/*
// 返回一個放大或者縮小的視圖
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
}
// 開始放大或者縮小
- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:
(UIView *)view
{
}
// 縮放結束時
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale
{
}
// 視圖已經(jīng)放大或縮小
- (void)scrollViewDidZoom:(UIScrollView *)scrollView
{
NSLog(@"scrollViewDidScrollToTop");
}
*/
// 是否支持滑動至頂部
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView
{
return YES;
}
// 滑動到頂部時調用該方法
- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView
{
NSLog(@"scrollViewDidScrollToTop");
}
// scrollView 已經(jīng)滑動
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
NSLog(@"scrollViewDidScroll");
}
// scrollView 開始拖動
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
NSLog(@"scrollViewWillBeginDragging");
}
// scrollView 結束拖動
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
NSLog(@"scrollViewDidEndDragging");
}
// scrollView 開始減速(以下兩個方法注意與以上兩個方法加以區(qū)別)
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
{
NSLog(@"scrollViewWillBeginDecelerating");
}
// scrollview 減速停止
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
NSLog(@"scrollViewDidEndDecelerating");
}