Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.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 无法通过动画同时满足约束_Ios_Swift_Autolayout - Fatal编程技术网

Ios 无法通过动画同时满足约束

Ios 无法通过动画同时满足约束,ios,swift,autolayout,Ios,Swift,Autolayout,我有一个按钮,按下时,旋转显示其他按钮最初隐藏在它后面使用自动布局 按钮添加了以下约束: var tennisButtonHiddenConstraint1 : NSLayoutConstraint? var tennisButtonHiddenConstraint2 : NSLayoutConstraint? var tennisButtonBottomAnchor : NSLayoutConstraint? var tennisButtonRightAnchor : NSLayoutCo

我有一个按钮,按下时,旋转显示其他按钮最初隐藏在它后面使用自动布局

按钮添加了以下约束:

var tennisButtonHiddenConstraint1 : NSLayoutConstraint?
var tennisButtonHiddenConstraint2 : NSLayoutConstraint?
var tennisButtonBottomAnchor : NSLayoutConstraint?
var tennisButtonRightAnchor : NSLayoutConstraint?
var tennisButtonWidthAnchor : NSLayoutConstraint?
var tennisButtonHeightAnchor : NSLayoutConstraint?


func setupViews(){
        self.mapView.addSubview(tennisButton)
        tennisButtonHiddenConstraint1 =  tennisButton.bottomAnchor.constraint(equalTo: self.mapView.bottomAnchor, constant: -50)
        tennisButtonHiddenConstraint1?.isActive = true

        tennisButtonHiddenConstraint2 = tennisButton.centerXAnchor.constraint(equalTo: self.mapView.centerXAnchor)
        tennisButtonHiddenConstraint2?.isActive = true

        tennisButtonRightAnchor =  tennisButton.rightAnchor.constraint(equalTo: self.addEventButton.leftAnchor, constant: -20)
        tennisButtonRightAnchor?.isActive = false

        tennisButtonBottomAnchor = tennisButton.bottomAnchor.constraint(equalTo: self.addEventButton.topAnchor, constant: 20)
        tennisButtonBottomAnchor?.isActive = false

        tennisButtonWidthAnchor  = tennisButton.widthAnchor.constraint(equalToConstant: 66)
        tennisButtonWidthAnchor?.isActive = false
        tennisButtonHeightAnchor  = tennisButton.heightAnchor.constraint(equalToConstant: 66)
        tennisButtonHeightAnchor?.isActive = false

        self.mapView.addSubview(addEventButton)
        addEventButton.bottomAnchor.constraint(equalTo: self.mapView.bottomAnchor, constant: -50).isActive = true
        addEventButton.centerXAnchor.constraint(equalTo: self.mapView.centerXAnchor).isActive = true
        addEventButton.widthAnchor.constraint(equalToConstant: 80).isActive = true
        addEventButton.heightAnchor.constraint(equalToConstant: 80).isActive = true
}
然后动画代码如下所示:

@objc func showAvailableActions(){
    if menuButtonShown == false {
        self.tennisButtonHiddenConstraint1?.isActive = false
        self.tennisButtonHiddenConstraint2?.isActive = false
        self.tennisButtonBottomAnchor?.isActive = true
        self.tennisButtonRightAnchor?.isActive = true
        self.tennisButtonHeightAnchor?.isActive = true
        self.tennisButtonWidthAnchor?.isActive = true
        menuButtonShown = true

        UIView.animate(withDuration: 0.5, animations: {
        self.addEventButton.transform = CGAffineTransform(rotationAngle:  .pi/4)
        })

        UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 1.0, initialSpringVelocity: 1.0, options: .curveEaseInOut, animations: {
            self.view.layoutIfNeeded()
    }, completion: nil)

    }else{

        self.tennisButtonHiddenConstraint1?.isActive = true
        self.tennisButtonHiddenConstraint2?.isActive = true
        self.tennisButtonBottomAnchor?.isActive = false
        self.tennisButtonRightAnchor?.isActive = false
        self.tennisButtonHeightAnchor?.isActive = false
        self.tennisButtonWidthAnchor?.isActive = false
        menuButtonShown = false


        UIView.animate(withDuration: 0.5, animations: {
            self.addEventButton.transform = CGAffineTransform.identity
        })
        UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 1.0, initialSpringVelocity: 1.0, options: .curveEaseInOut, animations: {
            self.view.layoutIfNeeded()
        }, completion: nil)

    }
}
Yoofit[7442:9349648] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x600000a10f50 Yoofit.AddEventButton:0x7f8584c3beb0.height == 80   (active)>",
    "<NSLayoutConstraint:0x600000a17520 UIButton:0x7f8584c3c3e0.bottom == Yoofit.AddEventButton:0x7f8584c3beb0.top + 20   (active)>",
    "<NSLayoutConstraint:0x600000a17750 Yoofit.AddEventButton:0x7f8584c3beb0.bottom == MKMapView:0x7f858505f200.bottom - 50   (active)>",
    "<NSLayoutConstraint:0x600000a6b980 UIButton:0x7f8584c3c3e0.bottom == MKMapView:0x7f858505f200.bottom - 50   (active)>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x600000a10f50 Yoofit.AddEventButton:0x7f8584c3beb0.height == 80   (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
2019-07-03 19:51:02.337695+0800 Yoofit[7442:9349648] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x600000a17930 Yoofit.AddEventButton:0x7f8584c3beb0.width == 80   (active)>",
    "<NSLayoutConstraint:0x600000a17430 UIButton:0x7f8584c3c3e0.right == Yoofit.AddEventButton:0x7f8584c3beb0.left - 20   (active)>",
    "<NSLayoutConstraint:0x600000a177f0 Yoofit.AddEventButton:0x7f8584c3beb0.centerX == MKMapView:0x7f858505f200.centerX   (active)>",
    "<NSLayoutConstraint:0x600000a174d0 UIButton:0x7f8584c3c3e0.width == 66   (active)>",
    "<NSLayoutConstraint:0x600000a6bf20 UIButton:0x7f8584c3c3e0.centerX == MKMapView:0x7f858505f200.centerX   (active)>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x600000a17930 Yoofit.AddEventButton:0x7f8584c3beb0.width == 80   (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
2019-07-03 19:51:02.341441+0800 Yoofit[7442:9349648] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x600000a17430 UIButton:0x7f8584c3c3e0.right == Yoofit.AddEventButton:0x7f8584c3beb0.left - 20   (active)>",
    "<NSLayoutConstraint:0x600000a177f0 Yoofit.AddEventButton:0x7f8584c3beb0.centerX == MKMapView:0x7f858505f200.centerX   (active)>",
    "<NSLayoutConstraint:0x600000a174d0 UIButton:0x7f8584c3c3e0.width == 66   (active)>",
    "<NSLayoutConstraint:0x600000a6bf20 UIButton:0x7f8584c3c3e0.centerX == MKMapView:0x7f858505f200.centerX   (active)>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x600000a174d0 UIButton:0x7f8584c3c3e0.width == 66   (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
2019-07-03 19:51:02.360114+0800 Yoofit[7442:9349648] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x600000a17430 UIButton:0x7f8584c3c3e0.right == Yoofit.AddEventButton:0x7f8584c3beb0.left - 20   (active)>",
    "<NSLayoutConstraint:0x600000a177f0 Yoofit.AddEventButton:0x7f8584c3beb0.centerX == MKMapView:0x7f858505f200.centerX   (active)>",
    "<NSLayoutConstraint:0x600000a6bf20 UIButton:0x7f8584c3c3e0.centerX == MKMapView:0x7f858505f200.centerX   (active)>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x600000a177f0 Yoofit.AddEventButton:0x7f8584c3beb0.centerX == MKMapView:0x7f858505f200.centerX   (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
当按钮显示时,一切正常,但当按钮隐藏时,我得到以下信息:

@objc func showAvailableActions(){
    if menuButtonShown == false {
        self.tennisButtonHiddenConstraint1?.isActive = false
        self.tennisButtonHiddenConstraint2?.isActive = false
        self.tennisButtonBottomAnchor?.isActive = true
        self.tennisButtonRightAnchor?.isActive = true
        self.tennisButtonHeightAnchor?.isActive = true
        self.tennisButtonWidthAnchor?.isActive = true
        menuButtonShown = true

        UIView.animate(withDuration: 0.5, animations: {
        self.addEventButton.transform = CGAffineTransform(rotationAngle:  .pi/4)
        })

        UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 1.0, initialSpringVelocity: 1.0, options: .curveEaseInOut, animations: {
            self.view.layoutIfNeeded()
    }, completion: nil)

    }else{

        self.tennisButtonHiddenConstraint1?.isActive = true
        self.tennisButtonHiddenConstraint2?.isActive = true
        self.tennisButtonBottomAnchor?.isActive = false
        self.tennisButtonRightAnchor?.isActive = false
        self.tennisButtonHeightAnchor?.isActive = false
        self.tennisButtonWidthAnchor?.isActive = false
        menuButtonShown = false


        UIView.animate(withDuration: 0.5, animations: {
            self.addEventButton.transform = CGAffineTransform.identity
        })
        UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 1.0, initialSpringVelocity: 1.0, options: .curveEaseInOut, animations: {
            self.view.layoutIfNeeded()
        }, completion: nil)

    }
}
Yoofit[7442:9349648] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x600000a10f50 Yoofit.AddEventButton:0x7f8584c3beb0.height == 80   (active)>",
    "<NSLayoutConstraint:0x600000a17520 UIButton:0x7f8584c3c3e0.bottom == Yoofit.AddEventButton:0x7f8584c3beb0.top + 20   (active)>",
    "<NSLayoutConstraint:0x600000a17750 Yoofit.AddEventButton:0x7f8584c3beb0.bottom == MKMapView:0x7f858505f200.bottom - 50   (active)>",
    "<NSLayoutConstraint:0x600000a6b980 UIButton:0x7f8584c3c3e0.bottom == MKMapView:0x7f858505f200.bottom - 50   (active)>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x600000a10f50 Yoofit.AddEventButton:0x7f8584c3beb0.height == 80   (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
2019-07-03 19:51:02.337695+0800 Yoofit[7442:9349648] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x600000a17930 Yoofit.AddEventButton:0x7f8584c3beb0.width == 80   (active)>",
    "<NSLayoutConstraint:0x600000a17430 UIButton:0x7f8584c3c3e0.right == Yoofit.AddEventButton:0x7f8584c3beb0.left - 20   (active)>",
    "<NSLayoutConstraint:0x600000a177f0 Yoofit.AddEventButton:0x7f8584c3beb0.centerX == MKMapView:0x7f858505f200.centerX   (active)>",
    "<NSLayoutConstraint:0x600000a174d0 UIButton:0x7f8584c3c3e0.width == 66   (active)>",
    "<NSLayoutConstraint:0x600000a6bf20 UIButton:0x7f8584c3c3e0.centerX == MKMapView:0x7f858505f200.centerX   (active)>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x600000a17930 Yoofit.AddEventButton:0x7f8584c3beb0.width == 80   (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
2019-07-03 19:51:02.341441+0800 Yoofit[7442:9349648] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x600000a17430 UIButton:0x7f8584c3c3e0.right == Yoofit.AddEventButton:0x7f8584c3beb0.left - 20   (active)>",
    "<NSLayoutConstraint:0x600000a177f0 Yoofit.AddEventButton:0x7f8584c3beb0.centerX == MKMapView:0x7f858505f200.centerX   (active)>",
    "<NSLayoutConstraint:0x600000a174d0 UIButton:0x7f8584c3c3e0.width == 66   (active)>",
    "<NSLayoutConstraint:0x600000a6bf20 UIButton:0x7f8584c3c3e0.centerX == MKMapView:0x7f858505f200.centerX   (active)>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x600000a174d0 UIButton:0x7f8584c3c3e0.width == 66   (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
2019-07-03 19:51:02.360114+0800 Yoofit[7442:9349648] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x600000a17430 UIButton:0x7f8584c3c3e0.right == Yoofit.AddEventButton:0x7f8584c3beb0.left - 20   (active)>",
    "<NSLayoutConstraint:0x600000a177f0 Yoofit.AddEventButton:0x7f8584c3beb0.centerX == MKMapView:0x7f858505f200.centerX   (active)>",
    "<NSLayoutConstraint:0x600000a6bf20 UIButton:0x7f8584c3c3e0.centerX == MKMapView:0x7f858505f200.centerX   (active)>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x600000a177f0 Yoofit.AddEventButton:0x7f8584c3beb0.centerX == MKMapView:0x7f858505f200.centerX   (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
Yoofit[7442:9349648][LayoutConstraints]无法同时满足约束。
可能下面列表中至少有一个约束是您不想要的。
试试这个:
(1) 看看每一个约束,试着找出你不期望的;
(2) 找到添加了不需要的约束的代码,然后修复它。
(
"",
"",
"",
""
)
将尝试通过打破约束进行恢复
在UIViewAlertForUnsatifiableConstraints处创建一个符号断点,以便在调试器中捕获该断点。
中列出的UIView上UIConstraintBasedLayoutDebugging类别中的方法也可能会有所帮助。
2019-07-03 19:51:02.337695+0800 Yoofit[7442:9349648][LayoutConstraints]无法同时满足约束。
可能下面列表中至少有一个约束是您不想要的。
试试这个:
(1) 看看每一个约束,试着找出你不期望的;
(2) 找到添加了不需要的约束的代码,然后修复它。
(
"",
"",
"",
"",
""
)
将尝试通过打破约束进行恢复
在UIViewAlertForUnsatifiableConstraints处创建一个符号断点,以便在调试器中捕获该断点。
中列出的UIView上UIConstraintBasedLayoutDebugging类别中的方法也可能会有所帮助。
2019-07-03 19:51:02.341441+0800 Yoofit[7442:9349648][LayoutConstraints]无法同时满足约束。
可能下面列表中至少有一个约束是您不想要的。
试试这个:
(1) 看看每一个约束,试着找出你不期望的;
(2) 找到添加了不需要的约束的代码,然后修复它。
(
"",
"",
"",
""
)
将尝试通过打破约束进行恢复
在UIViewAlertForUnsatifiableConstraints处创建一个符号断点,以便在调试器中捕获该断点。
中列出的UIView上UIConstraintBasedLayoutDebugging类别中的方法也可能会有所帮助。
2019-07-03 19:51:02.360114+0800 Yoofit[7442:9349648][LayoutConstraints]无法同时满足约束。
可能下面列表中至少有一个约束是您不想要的。
试试这个:
(1) 看看每一个约束,试着找出你不期望的;
(2) 找到添加了不需要的约束的代码,然后修复它。
(
"",
"",
""
)
将尝试通过打破约束进行恢复
在UIViewAlertForUnsatifiableConstraints处创建一个符号断点,以便在调试器中捕获该断点。
中列出的UIView上UIConstraintBasedLayoutDebugging类别中的方法也可能会有所帮助。

出现这种情况的原因是,在禁用已生效的旧约束之前,您正在激活新的(冲突的)约束

问题出在
else
块的开头,在将
tennisButtonHiddenConstraint1
tennisButtonHiddenConstraint2设置为活动状态之前,您需要先禁用其他

    self.tennisButtonBottomAnchor?.isActive = false
    self.tennisButtonRightAnchor?.isActive = false
    self.tennisButtonHeightAnchor?.isActive = false
    self.tennisButtonWidthAnchor?.isActive = false
    self.tennisButtonHiddenConstraint1?.isActive = true
    self.tennisButtonHiddenConstraint2?.isActive = true
它在第一次加载时工作,因为还没有添加其他约束(因此顺序无关紧要)

如果有疑问,在约束集之间切换时,请始终首先设置
。isActive=false