1. 程式人生 > >UIScrollerView中一些常用的手勢功能

UIScrollerView中一些常用的手勢功能

{
    [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
{

}

// 檢視已經放大或縮小
- (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"); 
}