【问题标题】:Resizing UIView with animation, subview won't animate用动画调整 UIView 的大小,子视图不会动画
【发布时间】:2023-04-02 01:53:01
【问题描述】:

使用 UIView 的 animateWithDuration:animations:completion:,我正在调整 UIView 和 UIView 的子视图,它是 UITableView 的子类。

UIView 可以很好地调整大小,但 UITableView 没有。它确实移动了一点,但框架没有正确更新并恢复到其原始状态。

编辑:如果我将调整大小移动到完成块......它可以工作。什么给了?

    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];
    }];

【问题讨论】:

    标签: ios objective-c uitableview uiview


    【解决方案1】:

    如果UIView 选中了Autoresize Subviews,请检查您的故事板。这意味着当视图本身被调整大小时,它会调整所有子视图的大小。这可以解释为什么它在完成块中起作用。

    【讨论】:

    • 已勾选,但取消勾选无效。
    • 您在使用自动布局吗?您可以将 UITableView 的宽度固定到 UIView 宽度,然后您不必手动更改它的框架。
    猜你喜欢
    • 1970-01-01
    • 2014-05-13
    • 2017-06-08
    • 1970-01-01
    • 2014-04-04
    • 1970-01-01
    • 1970-01-01
    • 2013-01-22
    • 1970-01-01
    相关资源
    最近更新 更多