2010-05-18 3 views

답변

5

예 ... 아래의 두 가지를 포함하는 방법을 구현의 UIScrollViewDelegate 사양을 확인하고 그에 따라있는 UIScrollView의 위임을 설정

// User stops dragging the table view. 

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

// Control slows to a halt after the user drags it 

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView; 

당신은 아마 scrollViewDidEndDecelerating에서 가장 관심을 가질 것입니다. 이들은 또한 UITableView에서 원래 어디서 발견했는지 (UITableView는 UIScrollView에서 상속 받음) 작동합니다.

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

    if (scrollView.contentOffset.x < 0) { 
    NSLog(@"bouncing left"); 
    } 

    if (scrollView.contentOffset.x > (scrollView.contentSize.width - scrollView.frame.size.width)) { 
    NSLog(@"bouncing right"); 
    } 
} 
+0

: 내용이있는 ScrollView 세트를 덮고 충분히 크지 않은 경우에도 비 제로 contentInsets로하고 경우에 작동합니다 고마워. 나는이 방법을 안다. 나는 다른 방법이 있다고 생각했다. 감사! :) –

28

스크롤 뷰가 수평으로 튀는 경우 내가 감지하는 방법이다 뷰의 내용을 업데이트하기 위해 스크롤 뷰에서 아래로 "바운스 (bounce)"합니다.

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

    CGPoint offset = aScrollView.contentOffset; 
    CGRect bounds = aScrollView.bounds; 
    CGSize size = aScrollView.contentSize; 
    UIEdgeInsets inset = aScrollView.contentInset; 
    float y = offset.y + bounds.size.height - inset.bottom; 
    float h = size.height; 

    //Distance in points before update-event occur 
    float reload_distance = 50; 
    // 
    if(y > h + reload_distance) { 
     NSLog(@"load more rows"); 
    } 
} 
8

저스틴의 방법에 대한 약간의 수정을 contentInset을 허용 : 수있을 것 분들을 위해

if(scrollView.contentOffset.x < -scrollView.contentInset.left) 
{ 
    NSLog(@"bounce left"); 
} 
if(scrollView.contentOffset.x > scrollView.contentSize.width - scrollView.frame.size.width + scrollView.contentInset.right) 
{ 
    NSLog(@"bounce right"); 
} 
1

오래된 질문을 (그리고 이벤트는. 한 번 해고)하지만 난 그냥 비슷한 문제로 실행하고 또한 스크롤 뷰의 내용을 스크롤보다 큰 것을 확인하는 것이 좋습니다 것을 추가하고 싶었 뷰의 프레임은 :

+ (BOOL) isScrollViewBouncing:(UIScrollView *)scrollView 
{ 
    return scrollView.contentOffset.y > scrollView.contentSize.height - scrollView.frame.size.height 
      && scrollView.contentSize.height > scrollView.frame.size.height; 
} 

이 이제 스크롤 뷰가 작은 경우 항상 true로 평가하지 않도록 스크롤 뷰 스크롤 - 수신 거부 상태에있을 정도로 큰 확인합니다. Glavid의 답변을 사용

건배

0

, 나는 또한 바닥에 튀는 추가하고, 카테고리있는 UIScrollView가 수직 및 수평 스크롤이 처리하는 내가 확장을 구현했습니다

#import "UIScrollView+Additions.h" 

@implementation UIScrollView (Additions) 

- (BOOL)isBouncing 
{ 
    BOOL isBouncingBottom = self.contentOffset.y >= self.contentSize.height - self.frame.size.height 
     && self.contentSize.height >= self.frame.size.height; 
    BOOL isBouncingTop = self.contentOffset.y <= 0; 

    BOOL isBouncing = isBouncingBottom || isBouncingTop; 
    return isBouncing; 
} 

@end 
9

로 추가.

목표 - C

@interface UIScrollView (Bouncing) 

@property (nonatomic, readonly) BOOL isBouncing; 
@property (nonatomic, readonly) BOOL isBouncingTop; 
@property (nonatomic, readonly) BOOL isBouncingLeft; 
@property (nonatomic, readonly) BOOL isBouncingBottom; 
@property (nonatomic, readonly) BOOL isBouncingRight; 

@end 

@implementation UIScrollView (Bouncing) 

- (BOOL)isBouncing 
{ 
    return self.isBouncingTop || self.isBouncingLeft || self.isBouncingBottom || self.isBouncingRight; 
} 

- (BOOL)isBouncingTop 
{ 
    return self.contentOffset.y < - self.contentInset.top; 
} 

- (BOOL)isBouncingLeft 
{ 
    return self.contentOffset.x < - self.contentInset.left; 
} 

- (BOOL)isBouncingBottom 
{ 
    BOOL contentFillsScrollEdges = self.contentSize.height + self.contentInset.top + self.contentInset.bottom >= CGRectGetHeight(self.bounds); 
    return contentFillsScrollEdges && self.contentOffset.y > self.contentSize.height - CGRectGetHeight(self.bounds) + self.contentInset.bottom; 
} 

- (BOOL)isBouncingRight 
{ 
    BOOL contentFillsScrollEdges = self.contentSize.width + self.contentInset.left + self.contentInset.right >= CGRectGetWidth(self.bounds); 
    return contentFillsScrollEdges && self.contentOffset.x > self.contentSize.width - CGRectGetWidth(self.bounds) + self.contentInset.right; 
} 

@end 

스위프트 3.0

extension UIScrollView { 
    var isBouncing: Bool { 
    return isBouncingTop || isBouncingLeft || isBouncingBottom || isBouncingRight 
    } 
    var isBouncingTop: Bool { 
    return contentOffset.y < -contentInset.top 
    } 
    var isBouncingLeft: Bool { 
    return contentOffset.x < -contentInset.left 
    } 
    var isBouncingBottom: Bool { 
    let contentFillsScrollEdges = contentSize.height + contentInset.top + contentInset.bottom >= bounds.height 
    return contentFillsScrollEdges && contentOffset.y > contentSize.height - bounds.height + contentInset.bottom 
    } 
    var isBouncingRight: Bool { 
    let contentFillsScrollEdges = contentSize.width + contentInset.left + contentInset.right >= bounds.width 
    return contentFillsScrollEdges && contentOffset.x > contentSize.width - bounds.width + contentInset.right 
    } 
}