satheesh kumar
satheesh kumar

Reputation: 113

UIscrollView animation not smoothly

Code:

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

    int diff = end-start;

    if (diff>0)
    {
        k = k + 95;
    }
    else {

        k = k - 95;
    }

     [scrollView setContentOffset:CGPointMake(k, 0) animated:YES];
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
        start = scrollView.contentOffset.x;
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
        end = scrollView.contentOffset.x;

}

I have a scrollview with 3 labels. leftSide 90 pixels width, center 90 pixels width and rightside 90 pixels width.Each label has 5 pixel gap.when scrollview scroll left or right i align next or previous label center of the screen.Logic is working fine.but animtation is not smooth and also there is a pause after starting animation.How do i solve this problem?.How do i speed up animation?any help will be appreciated.

Upvotes: 1

Views: 773

Answers (2)

Tushar
Tushar

Reputation: 3052

I think the better way would be to just use UIScrollView's

pagingEnabled = YES;

And you don't need the above delegate methods. Make sure you have set the contentSize.

Upvotes: 0

Vishnuvardhan
Vishnuvardhan

Reputation: 5107

You can adjust the speed of scrolling by the following way, by adjusting duration value.

[UIView animateWithDuration:0.5 animations:^{
        _scrolview.contentOffset = CGPointMake(k, 0);
    }];

Upvotes: 1

Related Questions