OGeek|极客世界-中国程序员成长平台

标题: ios - animateWithDuration setFrame 不起作用 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 14:46
标题: ios - animateWithDuration setFrame 不起作用

您好,我有一段代码,只有一行不工作...

[UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionCurveEaseOut animations:^{
    [label setFrame:CGRectMake(0, 0, frame.size.width, kStandardLabelHeight)]; //working
    [self.currentLabel setFrame:CGRectOffset(self.currentLabel.frame, frame.size.width, 0)]; //not working 
    [self.currentLabel setAlpha:0.0f]; //working
} completion:^(BOOL finished) {
    [self.currentLabel removeFromSuperview];
    self.currentLabel = label;
}];

我想不出什么问题了...



Best Answer-推荐答案


我发现:如果我关闭“使用自动布局”,那么它会神奇地工作,所以这个问题与自动布局有关。

经过搜索,我发现:http://weblog.invasivecode.com/post/42362079291/auto-layout-and-core-animation-auto-layout-was

为您的 View 添加约束导出映射,然后不使用 setFrame,更新约束就可以解决问题!

下面是我的最终实现(_topConstraint 是表格 View 的顶部垂直空间约束):

- (IBAction)switchButtonTouchedid)sender
{
    if (_topConstraint.constant <= 0)
        _topConstraint.constant = _buttonView.frame.size.height;
    else
        _topConstraint.constant = 0;

    [_tableView setNeedsUpdateConstraints];
    [UIView animateWithDuration:0.5f animations:^(void){
        [_tableView layoutIfNeeded];
    } completion:^(BOOL finished){
    }];
}

关于ios - animateWithDuration setFrame 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18946717/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4