Tuesday, June 4, 2013

UIScrollView bounces example in Objective C (iOS).


UIScrollView bounces

A Boolean value that controls whether the scroll view bounces past the edge of content and back again.

@property(nonatomic) BOOL bounces

Discussion of [UIScrollView bounces]
If the value of this property is YES, the scroll view bounces when it encounters a boundary of the content. Bouncing visually indicates that scrolling has reached an edge of the content. If the value is NO, scrolling stops immediately at the content boundary without bouncing. The default value is YES.
UIScrollView bounces example.
- (id)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        self.pagingEnabled = YES;
        self.bounces = YES;
    }
    return self;
}

Example of [UIScrollView bounces].
_scrollView = [[UIScrollView alloc]init];
_scrollView.pagingEnabled = YES;
_scrollView.bounces = NO; //Here
then, no bounce any more!

UIScrollView bounces example.
scroll = [[UIScrollView alloc] init];
scroll.pagingEnabled = YES;
scroll.showsHorizontalScrollIndicator = NO;
scroll.showsVerticalScrollIndicator = NO;
scroll.scrollsToTop = NO;
scroll.alwaysBounceHorizontal= YES;
scroll.bounces = YES;
scroll.delegate = self;
CGRect frame = CGRectMake(0.0, 0.0, 768, 1004);
scroll.frame = frame;
[self.view addSubview:scroll];

UIView *view1 = [[UIView alloc] init];
view1.frame = CGRectMake(0, 0.0, 768, 1004);
view1.clipsToBounds = YES;
view1.backgroundColor = [UIColor redColor];
[scroll addSubview:view1];

scroll.contentSize = CGSizeMake(768 * 1, 1004);

End of UIScrollView bounces example article.