2016-02-14 2 views
0

Я пытаюсь перекрестно увязать изображения, когда пользователь выбирает новый фильтр изображения.найти ошибку при попытке добавить еще один UIImageView поверх первого

Таким образом, я создал второй объект ImageView поверх первого и анимировал альфа верхнего вида, чтобы показать или скрыть вид снизу.

вот моя showSecondImageView функция():

func showSecondImageView() { 
     view.addSubview(secondImageView) 

     secondImageView.translatesAutoresizingMaskIntoConstraints = false 


     let bottomConstraint = secondImageView.topAnchor.constraintEqualToAnchor(imageView.topAnchor) 
     let leftConstraint = secondImageView.leftAnchor.constraintEqualToAnchor(imageView.leftAnchor) 
     let rightConstraint = secondImageView.rightAnchor.constraintEqualToAnchor(imageView.rightAnchor) 
     let heightConstraint = secondImageView.heightAnchor.constraintEqualToAnchor(imageView.heightAnchor) 

     NSLayoutConstraint.activateConstraints([bottomConstraint,leftConstraint,rightConstraint,heightConstraint]) 

     view.layoutIfNeeded() 


     self.secondImageView.alpha = 0 
     UIView.animateWithDuration(0.4) { 
      self.secondImageView.alpha = 1.0 
    } 

} 

Вывод:

2016-02-14 23:50:17.444 Filterer[3484:344297] 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:0x7fdf58c33c80 UIImageView:0x7fdf58c30ed0.leading == UIView:0x7fdf58c22480.leading>", 
    "<NSLayoutConstraint:0x7fdf58c0ff70 UIImageView:0x7fdf58c30ed0.trailing == UIView:0x7fdf58c22480.trailing>", 
    "<NSLayoutConstraint:0x7fdf58c1d7d0 H:|-(0)-[UIView:0x7fdf58c22480] (Names: '|':UIView:0x7fdf58c19270)>", 
    "<NSLayoutConstraint:0x7fdf58c1d820 H:[UIView:0x7fdf58c22480]-(0)-| (Names: '|':UIView:0x7fdf58c19270)>", 
    "<NSLayoutConstraint:0x7fdf58f30850 H:[UIImageView:0x7fdf58f30440(600)]>", 
    "<NSLayoutConstraint:0x7fdf58c5e350 UIImageView:0x7fdf58f30440.left == UIImageView:0x7fdf58c30ed0.left>", 
    "<NSLayoutConstraint:0x7fdf58c79c40 UIImageView:0x7fdf58f30440.right == UIImageView:0x7fdf58c30ed0.right>", 
    "<NSLayoutConstraint:0x7fdf58c32190 'UIView-Encapsulated-Layout-Width' H:[UIView:0x7fdf58c19270(375)]>" 
) 

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7fdf58f30850 H:[UIImageView:0x7fdf58f30440(600)]> 

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. 
2016-02-14 23:50:17.446 Filterer[3484:344297] 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. 
(
    "<_UILayoutSupportConstraint:0x7fdf58c165e0 V:[_UILayoutGuide:0x7fdf58c0fde0(0)]>", 
    "<_UILayoutSupportConstraint:0x7fdf58c2eb70 _UILayoutGuide:0x7fdf58c0fde0.bottom == UIView:0x7fdf58c19270.bottom>", 
    "<NSLayoutConstraint:0x7fdf58c35fc0 V:[UIButton:0x7fdf58c35d20'New Photo'(45)]>", 
    "<NSLayoutConstraint:0x7fdf58c31740 V:[UIStackView:0x7fdf58c30420]-(0)-| (Names: '|':UIView:0x7fdf58c22480)>", 
    "<NSLayoutConstraint:0x7fdf58c318a0 V:|-(0)-[UIStackView:0x7fdf58c30420] (Names: '|':UIView:0x7fdf58c22480)>", 
    "<NSLayoutConstraint:0x7fdf58c0ffc0 V:|-(0)-[UIImageView:0x7fdf58c30ed0] (Names: '|':UIView:0x7fdf58c19270)>", 
    "<NSLayoutConstraint:0x7fdf58c26f70 V:[UIImageView:0x7fdf58c30ed0]-(0)-[UIView:0x7fdf58c22480]>", 
    "<NSLayoutConstraint:0x7fdf58c26fc0 V:[UIView:0x7fdf58c22480]-(0)-[_UILayoutGuide:0x7fdf58c0fde0]>", 
    "<NSLayoutConstraint:0x7fdf58f30ab0 V:[UIImageView:0x7fdf58f30440(555)]>", 
    "<NSLayoutConstraint:0x7fdf58c74640 UIImageView:0x7fdf58f30440.height == UIImageView:0x7fdf58c30ed0.height>", 
    "<NSLayoutConstraint:0x7fdf58c323e0 'UISV-canvas-connection' UIStackView:0x7fdf58c30420.top == UIButton:0x7fdf58c35d20'New Photo'.top>", 
    "<NSLayoutConstraint:0x7fdf58c3dd40 'UISV-canvas-connection' V:[UIButton:0x7fdf58c35d20'New Photo']-(0)-| (Names: '|':UIStackView:0x7fdf58c30420)>", 
    "<NSLayoutConstraint:0x7fdf58c3fe60 'UIView-Encapsulated-Layout-Height' V:[UIView:0x7fdf58c19270(667)]>" 
) 

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7fdf58c35fc0 V:[UIButton:0x7fdf58c35d20'New Photo'(45)]> 

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. 
2016-02-14 23:50:17.461 Filterer[3484:344297] 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. 
(
    "<_UILayoutSupportConstraint:0x7fdf58c165e0 V:[_UILayoutGuide:0x7fdf58c0fde0(0)]>", 
    "<_UILayoutSupportConstraint:0x7fdf58c2eb70 _UILayoutGuide:0x7fdf58c0fde0.bottom == UIView:0x7fdf58c19270.bottom>", 
    "<NSLayoutConstraint:0x7fdf58c17050 V:[UIButton:0x7fdf58c16940'Edit'(45)]>", 
    "<NSLayoutConstraint:0x7fdf58c31740 V:[UIStackView:0x7fdf58c30420]-(0)-| (Names: '|':UIView:0x7fdf58c22480)>", 
    "<NSLayoutConstraint:0x7fdf58c318a0 V:|-(0)-[UIStackView:0x7fdf58c30420] (Names: '|':UIView:0x7fdf58c22480)>", 
    "<NSLayoutConstraint:0x7fdf58c0ffc0 V:|-(0)-[UIImageView:0x7fdf58c30ed0] (Names: '|':UIView:0x7fdf58c19270)>", 
    "<NSLayoutConstraint:0x7fdf58c26f70 V:[UIImageView:0x7fdf58c30ed0]-(0)-[UIView:0x7fdf58c22480]>", 
    "<NSLayoutConstraint:0x7fdf58c26fc0 V:[UIView:0x7fdf58c22480]-(0)-[_UILayoutGuide:0x7fdf58c0fde0]>", 
    "<NSLayoutConstraint:0x7fdf58f30ab0 V:[UIImageView:0x7fdf58f30440(555)]>", 
    "<NSLayoutConstraint:0x7fdf58c74640 UIImageView:0x7fdf58f30440.height == UIImageView:0x7fdf58c30ed0.height>", 
    "<NSLayoutConstraint:0x7fdf58c3fa40 'UISV-alignment' UIButton:0x7fdf58c35d20'New Photo'.bottom == UIButton:0x7fdf58c16940'Edit'.bottom>", 
    "<NSLayoutConstraint:0x7fdf58c404d0 'UISV-alignment' UIButton:0x7fdf58c35d20'New Photo'.top == UIButton:0x7fdf58c16940'Edit'.top>", 
    "<NSLayoutConstraint:0x7fdf58c323e0 'UISV-canvas-connection' UIStackView:0x7fdf58c30420.top == UIButton:0x7fdf58c35d20'New Photo'.top>", 
    "<NSLayoutConstraint:0x7fdf58c3dd40 'UISV-canvas-connection' V:[UIButton:0x7fdf58c35d20'New Photo']-(0)-| (Names: '|':UIStackView:0x7fdf58c30420)>", 
    "<NSLayoutConstraint:0x7fdf58c3fe60 'UIView-Encapsulated-Layout-Height' V:[UIView:0x7fdf58c19270(667)]>" 
) 

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7fdf58c17050 V:[UIButton:0x7fdf58c16940'Edit'(45)]> 

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. 

enter image description here

enter image description here

первая картина является ошибка одна, вторая картина это то, что я хочу, чтобы это выглядело, как исправить Это ?

enter image description here

+0

«Выход говорит« Невозможно одновременно удовлетворить ограничения »« Это говорит больше, чем это. Гораздо больше. Покажите все сообщение, пожалуйста. Также, пожалуйста, опишите иерархию представлений более точно и полностью. – matt

+0

Я только что добавил скриншот иерархии представлений и всего сообщения :-) – luiyezheng

+0

Мне кажется, что вы находитесь в гораздо более глубоком doodoo, чем вы ранее допускали. Вы говорите мне, что у вас никогда не было этих сообщений, прежде чем вы добавили второе изображение? – matt

ответ

0

Для точно такая же проблема у вас есть! Я пошел с опцией UIView.transitionWithView упомянутой выше:

UIView.transitionWithView(myImageView, 
     duration: 0.4, 
     options: UIViewAnimationOptions.TransitionCrossDissolve, 
     animations: { self.myImageView.image = toShow}, 
     completion: { completed in 
      //do nothing here}) 

Если переменный «toShow» является новым образом. Это позволяет избежать необходимости управлять подвью.

Смежные вопросы