Randy
Randy

Reputation: 4535

Change UIScrollView contentSize with animation

Is it possible to change a UIScrollView's contentSize with an animation so the size decreases / increases on a certain period, something like

UIView.animateWithDuration(0.3, animations: {
   scrollView.contentSize.width -= 100.0
}

Doesn't work. I don't know if there's a way to do that ?

Upvotes: 4

Views: 1036

Answers (1)

Johnny Rockex
Johnny Rockex

Reputation: 4196

Try the transitionWithView method:

      float newHeight = scroller.contentSize.height - someChangeFloat;
      [UIView transitionWithView:scroller
                          duration:0.3f
                           options:UIViewAnimationOptionCurveEaseOut
                        animations:^{
                            scroller.contentSize = CGSizeMake(0, newHeight);
                        }
                        completion:^(BOOL finished){
                        }];

Upvotes: 1

Related Questions