自动布局在iOS 10中不设置动画,但在iOS 9中工作正常

自动布局在iOS 10中不设置动画,但在iOS 9中工作正常,ios,objective-c,uiview,autolayout,ios-autolayout,Ios,Objective C,Uiview,Autolayout,Ios Autolayout,我正在使用这段代码,但在iOS10上,它并没有设置动画,只是增加和减少mySubview1的高度。为什么? 同样的代码在iOS9中运行良好,对于iOS10,它是视图的超级视图,您必须强制布局 - (IBAction)btnA:(id)sender { if(self.height.constant == 300) { self.height.constant = 50; } else { self.height.constant = 300;

我正在使用这段代码,但在
iOS10
上,它并没有设置动画,只是增加和减少mySubview1的高度。为什么?


同样的代码在iOS9中运行良好,对于iOS10,它是视图的超级视图,您必须强制布局

- (IBAction)btnA:(id)sender {
    if(self.height.constant == 300) {
         self.height.constant = 50;
    } else {
         self.height.constant = 300;
    }

    [self.subView1 setNeedsUpdateConstraints];

    [UIView animateWithDuration:1.0 animations:^{
        [self.subView1 layoutIfNeeded];
    }];
}
我相信这种行为是由Xcode8-iOS10布局的变化引起的

参考资料:


你能试着把这条线去掉,看看它是否管用吗。[self.subView1 setNeedsUpdateConstraints];这个问题过去也存在于iOS 7中。检查此项如果我的视图是UITableViewCell的子视图,那么我应该怎么做?我用1吗。[cell.subView.superView layoutifneed]、2[cell layoutifneed]或3。[cell.superview布局需要]?我会用哪一种?我使用的是相同的代码,但不是iOS 10.1。请帮帮我。Thanks@JekilPatel你试过什么?您想在uitableviewcell内设置子视图动画,对吗?试试[cell.contentview layoutifneed]@Teffi是的,你说得对。我正在尝试在UITableViewCell中设置子视图的动画。谢谢你的回复。让我试试你提供的,让你知道。谢谢lot@Teffi我曾尝试使用[cell.contentview layoutifneed]在UITableViewCell中将tableview作为子视图设置动画,但不幸的是,它不起作用。我的代码和你回答的一样。
//Force apply all constraints prior to the change in constant.
[self.view.superview layoutIfNeeded];

//Update constant
self.height.constant = 0;

[UIView animateWithDuration:1.0 animations:^{
    [self.view.superview layoutIfNeeded];
}