Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7674565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:45:58+00:00 2026-05-31T16:45:58+00:00

I have a subclass of UIScrollView that I’m using for images slideshow, with infinite

  • 0

I have a subclass of UIScrollView that I’m using for images slideshow, with infinite scrolling and circular slideshow.

I used to animate the transition in this way: (Because I wanted the transition to be slower)

[UIView animateWithDuration:1.0 
                      delay:0 options:(UIViewAnimationCurveEaseOut)
                 animations:^{
                         self.scrollView.contentOffset = newOffset;}
                 completion:NULL];

And it worked just fine.

Then I watched the lecture “Advanced Scrolling Techniques” from WWDC 2011, and they recommend to implement infinite scrolling by overriding layoutSubviews.

So I changed my implementation and override layoutSubviews

Once I did that the transition animation stopped working.

If I comment out my custom layoutSubviews – It’s working again!

Why??

What can I do to make my own scrolling animation while overriding layoutSubviews?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T16:45:59+00:00Added an answer on May 31, 2026 at 4:45 pm

    OK, I think I found the problem, and a possible fix.

    The key to understand the problem is understanding that when you call

    [UIView animateWithDuration...]
    

    All the properties that you change inside the animation block, are changed immediately. They do not change as the animation actually executing (visually).

    So in my case, I’m animating the contentOffset to my target value.
    This operation invokes layoutSubviews immediately.

    In my implementation of layoutSubviews I’m checking to see if enough movement has been accumulated. If so – I’m rearranging my ImageViews, and set the contentOffset to its initial value. Once I do that there is nothing to animate anymore, because nothing has changed!

    1. Animate contentOffset to X:
      • calls setContentOffset to X:
        • invokes layoutSubview
          • Sets the contentOffset back to Y! (after rearranging the views)
      • Nothing to animate at this point…

    Possible Fix

    I’m not sure if it is the right way to do it, but its working working.
    So what we need to do is to ensure that no changes will be made in layoutSubviews while we are in the middle of animation block.

    So I created a BOOL instance variable named isAnimating, and set it appropriately in the animation block:

    self.isAnimating = YES;
    [UIView animateWithDuration:self.transitionDuration 
                          delay:0 
                        options:(UIViewAnimationOptionCurveEaseOut) 
                     animations:^{
        self.contentOffset = newOffset;
    }
    
                     completion:^(BOOL finished) {
            self.isAnimating = NO;
            [self setNeedsLayout];
    }];
    

    Now in layoutSubviews we need to take isAnimating into account:

    -(void) layoutSubviews
    {
        [super layoutSubviews];
        if (self.isAnimating == NO)
        {
            [self rearrangeIfNecessary];
        }
    }
    

    And it’s working again!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UIScrollView subclass that I am programmatically scrolling using UIView animations. I'd
HI All. I have subclass of UIScrollView. IN this class I have added some
I have a UIScrollView that I need to subclass and within the subclass I
I'm using an UIScrollView and I have an image that indicates to the user
I have a subclass of UIScrollView that overrides touchesBegan:withEvent: touchesMoved:withEvent: touchesEnded:withEvent: Overriding these three
I want to create a subclass of UITableView or UIScrollView that will have some
So I have a UIViewController subclass called MyTabBarViewController that has a UIScrollView. Inside of
i have an uiscrollview with a uiimageview inside. I subclass the uiscrollview but i
I have a subclass with an over-ridden method that I know always returns a
I have a subclass of UITableViewController. I have code that can add/remove a UISearchBar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.