Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animate contentInset

I'd like to animate the contentInset of a scrollView which belongs to a UIWebView. I tried the following code, but unfortunately the inset just jumps when it runs

UIViewAnimationOptions options = UIViewAnimationOptionBeginFromCurrentState;
[UIView animateWithDuration:10.0 delay:0 options:options animations:^
 {
     self.webView.scrollView.contentInset = UIEdgeInsetsMake(100 ,120,120,120);
 }
                 completion:nil];

Does anyone know how i can make a smooth animation of contentInset? I also tried the option AllowAnimatedContent with no luck

like image 628
user3159270 Avatar asked Oct 24 '25 01:10

user3159270


2 Answers

Try something like this:

CGFloat height = 80.0f //change to whichever value you want

[UIView animateWithDuration:0.2 animations:^{
    [self.peopleCollectionView setContentInset:UIEdgeInsetsMake(height, 0, 0, 0)];
}];
[self.peopleCollectionView setContentOffset:CGPointMake(0, -height) animated:YES];
like image 118
royherma Avatar answered Oct 26 '25 16:10

royherma


Swift 5.1 🔶

UIView.animate({
     self.tableView.contentInset = .init(top: tableViewOffset, left: 0, bottom: 0, right: 0)
     self.tableView.setContentOffset(.init(x: 0, y: -tableViewOffset), animated: false)
  }, onComplete: { Swift.print("Anim completed") })
like image 30
Sentry.co Avatar answered Oct 26 '25 15:10

Sentry.co



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!