horseshoe7
horseshoe7

Reputation: 2837

Incorrect Resizing of UIScrollView subviews while resizing the scrollView's frame

I have a situation where I have a UIView subclass with a UIScrollView as a member.

I animate the resizing of the UIView and resize the scrollview with it. The UIScrollView is an infinite image gallery (i.e. 3 Views that swap content in and out as paging occurs)

[UIView animateWithDuration: ...

when I animate the code, in the animations block I have

myView.frame = someNewFrame;

I thought that the animation will interpolate the intermediate frame sizes as it animates. i.e. make the call during every frame of the animation:

[myView setFrame: someIntermediateFrame];

So I overrode myView's setFrame method:

-(void)setFrame:(CGRect)frame
{
    [super setFrame:frame];

    [self resizeSubviews];
}

- (void)resizeSubviews
{
    CGRect frame = self.bounds;

    scrollView.frame = frame;
    scrollView.contentSize = CGSizeMake(frame.size.width * 3.0, frame.size.height);  // 3 pages
    [scrollView setContentOffset:CGPointMake(frame.size.width, 0.0) animated:NO];  // set contentOffset to middlePage
    [scrollView setNeedsDisplay];    // just in case.  don't know if this is necessary.  Currently not helpful.

    frame.origin.x = 0.0;
    frame.origin.y = 0.0;

    pageZeroRect = frame;
    self.pageZero.frame = frame;

    frame.origin.x += frame.size.width;   
    pageOneRect = frame;
    self.pageOne.frame = frame;

    frame.origin.x += frame.size.width;
    pageTwoRect = frame;
    self.pageTwo.frame = frame;
}

No animation occurs other than the containing view. The scrollview (and subviews) just jumps to its final value.

Any ideas what's going wrong? It just doesn't make sense. Everything looks ok, but there must be some other stuff going on under the hood that I don't know about. I've been programming iOS for 1.5 years now and so am not super experienced, but not THAT dumb either.

Upvotes: 1

Views: 2518

Answers (2)

horseshoe7
horseshoe7

Reputation: 2837

I'm looking at this question a year later, a year smarter, and would think the answer would be to override layoutSubviews of my UIView subclass.

or set the UIView's autoresizeSubviews property to YES, and set the correct autoresizing masks of the subviews.

Upvotes: 1

Vincent Bernier
Vincent Bernier

Reputation: 8664

Have you try not to overwrite the setFrame method?

if it's not working then, try to set the final frame of all your subviews in your animation block.

Upvotes: 0

Related Questions