Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用Swift设置约束更改(第二项)的动画?_Ios_Swift_Interface Builder_Uiviewanimation_Nslayoutconstraint - Fatal编程技术网

Ios 使用Swift设置约束更改(第二项)的动画?

Ios 使用Swift设置约束更改(第二项)的动画?,ios,swift,interface-builder,uiviewanimation,nslayoutconstraint,Ios,Swift,Interface Builder,Uiviewanimation,Nslayoutconstraint,我在IB中定义了一个约束,如下所示。如何以编程方式将此约束中的“第二项”更改为另一个对象(有效地将第一项向上移动到屏幕上)设置动画 下面是我尝试过的代码,其中“categoryTableViewTop”是NSLayoutConstraint。我得到错误“无法分配给此表达式的结果” 您没有更改代码中的约束常量。您必须这样更改它: categoryTableViewTop.secondItem.constant = categoryHeader.top.constant self.view.la

我在IB中定义了一个约束,如下所示。如何以编程方式将此约束中的“第二项”更改为另一个对象(有效地将第一项向上移动到屏幕上)设置动画

下面是我尝试过的代码,其中“categoryTableViewTop”是NSLayoutConstraint。我得到错误“无法分配给此表达式的结果”


您没有更改代码中的约束常量。您必须这样更改它:

categoryTableViewTop.secondItem.constant = categoryHeader.top.constant
self.view.layoutIfNeeded()
UIView.animateWithDuration(5, animations: { _ in
        // change your constraints here
        myTopConstraint.constant = 50.0
        self.view.layoutIfNeeded()
    }, completion: nil)
我假设
secondItem
top
是来自约束的
IBOutlets

要设置约束的动画,必须按如下方式更改约束:

categoryTableViewTop.secondItem.constant = categoryHeader.top.constant
self.view.layoutIfNeeded()
UIView.animateWithDuration(5, animations: { _ in
        // change your constraints here
        myTopConstraint.constant = 50.0
        self.view.layoutIfNeeded()
    }, completion: nil)

有关详细信息,请阅读或阅读此。

您没有更改代码中的约束常量。您必须这样更改它:

categoryTableViewTop.secondItem.constant = categoryHeader.top.constant
self.view.layoutIfNeeded()
UIView.animateWithDuration(5, animations: { _ in
        // change your constraints here
        myTopConstraint.constant = 50.0
        self.view.layoutIfNeeded()
    }, completion: nil)
我假设
secondItem
top
是来自约束的
IBOutlets

要设置约束的动画,必须按如下方式更改约束:

categoryTableViewTop.secondItem.constant = categoryHeader.top.constant
self.view.layoutIfNeeded()
UIView.animateWithDuration(5, animations: { _ in
        // change your constraints here
        myTopConstraint.constant = 50.0
        self.view.layoutIfNeeded()
    }, completion: nil)

有关详细信息,请阅读或参阅。

约束不允许您更改代码中的第二项,因为它是只读属性

我还没有在动画中尝试过这一点,但在其他动态布局中,可以在interface builder中使用不同的SecondItem创建两个不同的约束,并在代码中更改它们的优先级。如果同样的方法适用于动画,您可以尝试


使用优先级750和250,因为这些约束被视为可选项。

约束不允许您更改代码中的第二项,因为它是只读属性

我还没有在动画中尝试过这一点,但在其他动态布局中,可以在interface builder中使用不同的SecondItem创建两个不同的约束,并在代码中更改它们的优先级。如果同样的方法适用于动画,您可以尝试


使用优先级750和250,因为这些约束被视为可选项。

谢谢,但我不想更改约束常量,我想更改约束项/对象。categoryTableViewTop是一个来自约束的IBOutlet。如果您想在屏幕上移动某些内容,正如您在问题中所说,您必须更新约束常量值。你不能只把一个门店分配给另一个门店,希望得到同样的结果。约束是计算出来的,这就是为什么必须指定计算值而不是对象本身。谢谢,但我不想更改约束常量,我想更改约束项/对象。categoryTableViewTop是一个来自约束的IBOutlet。如果您想在屏幕上移动某些内容,正如您在问题中所说,您必须更新约束常量值。你不能只把一个门店分配给另一个门店,希望得到同样的结果。约束是计算出来的,这就是为什么必须指定计算值而不是对象本身。“使用优先级750和250,因为这些约束被视为可选的。”正确的解决方案是“使用优先级750和250,因为这些约束被视为可选的。”是正确的解决方案吗