iOS使用代碼調整約束做動畫效果時出現Unable to simultaneously satisfy constraints.


出現這個問題時, 首先應該仔細看錯誤, 去除多余的存在沖突的約束, 

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. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSLayoutConstraint:0x170097340 V:|-(0)-[UICollectionView:0x127981200]   (Names: '|':UIView:0x1275336e0 )>",
    "<NSLayoutConstraint:0x170095680 V:[UICollectionView:0x127981200]-(38)-|   (Names: '|':UIView:0x1275336e0 )>",
    "<NSLayoutConstraint:0x17009d830 V:[_UILayoutGuide:0x12753f2d0]-(0)-[UIView:0x1275336e0]>",
    "<NSLayoutConstraint:0x1700973e0 V:[UIView:0x1275336e0]-(416)-[_UILayoutGuide:0x12753f090]>",
    "<_UILayoutSupportConstraint:0x1742bda60 V:[_UILayoutGuide:0x12753f2d0(0)]>",
    "<_UILayoutSupportConstraint:0x1742b9560 V:|-(0)-[_UILayoutGuide:0x12753f2d0]   (Names: '|':UIView:0x1275ce900 )>",
    "<_UILayoutSupportConstraint:0x1742bdbe0 V:[_UILayoutGuide:0x12753f090(0)]>",
    "<_UILayoutSupportConstraint:0x1742bd9a0 _UILayoutGuide:0x12753f090.bottom == UIView:0x1275ce900.bottom>",
    "<NSLayoutConstraint:0x174284d80 'UIView-Encapsulated-Layout-Height' V:[UIView:0x1275ce900(416)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x170095680 V:[UICollectionView:0x127981200]-(38)-|   (Names: '|':UIView:0x1275336e0 )>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

 

這些都做完了發現還是報錯的話, 看一下代碼里改變約束的順序

- (void)updateViewConstraints {
    [super updateViewConstraints];
    //隱藏篩選框
    _siftTopCons.constant = -ScreenHeight+64;//頂部先上去
    _siftBottomCons.constant = ScreenHeight-64;//底部再上來

}

比如這個地方, 我讓這個View整體往上移動一個屏幕高度, 使其隱藏, 那么應該先把頂部的約束設置完, 再設置底部, 同理, 當要顯示的時候, 整個View往下移動一個屏幕高度, 就應該先設置底部的約束, 再設置頂部, 總之就是不要讓整個View的大小在設置的過程中發生可能的 尺寸變小

     
    
     _siftBottomCons.constant = 0;//底部先出來 _siftTopCons.constant = 0;//頂部再向下 [UIView animateWithDuration:0.27 animations:^{ [self.view layoutIfNeeded]; }];

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM