简体   繁体   中英

Resizing UIView with animation, subview won't animate

Using UIView's animateWithDuration:animations:completion: , I'm resizing a UIView and a subview of that UIView which is a subclass of UITableView.

The UIView resizes fine, but the UITableView doesn't. It does move around a little, but the frame does not update properly and reverts to its original state.

Edit: if I move the resizing to the completion block.... it works. What gives?

    tweetTable.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    [tweetTable endUpdates];
    [UIView animateWithDuration:DURATION animations:^{
        CGRect leftFrame = leftPane.frame;
        leftFrame.size.width = self.view.frame.size.width - MARGIN;
        leftPane.frame = leftFrame;
        leftPaneButton.frame = leftFrame;

        CGRect tweetFrame = tweetTable.frame;
        tweetFrame.size.width = leftPane.frame.size.width;
        NSLog(@"%f to %f", tweetTable.frame.size.width, leftPane.frame.size.width);
        tweetTable.frame = tweetFrame;
        tweetTable.backgroundColor = [UIColor redColor];
        tweetTable.alpha = 0.5f;

        sideInfo.center = CGPointMake(self.view.frame.size.width - MARGIN + (sideInfo.frame.size.width / 2), sideInfo.center.y);
        rightPaneButton.center = sideInfo.center;
    } completion:^(BOOL finished) {
        leftExtended = TRUE;
        [tweetTable beginUpdates];
    }];

Check in your storyboard if the UIView has Autoresize Subviews checked. That means that it resizes all of its subviews when the view itself gets resized. That would explain why it works in the completion block.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM