ios - animateWithDuration setFrame 不工作

标签 ios uiview uiviewanimation

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

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

我不知道哪里出了问题......

最佳答案

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

经过搜索,我找到了这个:http://weblog.invasivecode.com/post/42362079291/auto-layout-and-core-animation-auto-layout-was

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

下面是我最后的实现(_topConstraint是tableview的顶部垂直空间约束):

- (IBAction)switchButtonTouched:(id)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/

相关文章:

objective-c - 绘制矩形时如何避免颜色混合?

ios - 如何为 UIView 关键帧动画设置动画曲线 (`func UIView.animateKeyframes()` )

ios - 您好,我正在使用 Collection View 单元格,我想记录其中有多少被点击 "made true"并返回下一个 View Controller

iphone - PullRefreshTableView 编辑

iphone - 如何在UITableView下面添加UIButton?

ios - 创建 UIView 和 subview 需要几秒钟是正常的吗?

ios - iOS 上的动画持续时间

ios - 如何缩放和更改父 View 的原点并在 subview 中实现?

ios - 有没有办法以编程方式注销推送通知设备?

ios - 观看连接 session 问题