简体   繁体   English

使用动画调整UIView的大小,子视图不会动画

[英]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. 使用UIView的animateWithDuration:animations:completion:我正在调整UIView的大小以及该UIView的子视图,该子视图是UITableView的子类。

The UIView resizes fine, but the UITableView doesn't. UIView可以调整大小,但UITableView不能。 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. 在情节提要中检查UIView是否已选中“ 自动调整大小子视图” 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. 那可以解释为什么它在完成模块中起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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