Ошибка swift2 ограничивает SnapKit

Я использую SnapKit для добавления ограничений к изображению. У меня есть UIViewController.

У меня есть этот код:

imagenPrincipal.contentMode = .ScaleToFill
let URL = NSURL(string: oferta!.imagen)!
let placeholderImage = UIImage(named: "placeholder")!
imagenPrincipal.sd_setImageWithURL(URL, placeholderImage: placeholderImage, completed: nil)

let altoNuevo = 120.0
let anchoNuevo = 230.0

print(imagenPrincipal.frame.size.height)//->140.0
imagenPrincipal.frame.size.height = CGFloat(altoNuevo)
print(imagenPrincipal.frame.size.height)//->120.0

imagenPrincipal.snp_makeConstraints { (make) -> Void in
    make.center.equalTo(self.view)
    make.height.equalTo(imagenPrincipal.frame.size.height)
}

Проблема в том, что я не изменяю размер изображения до нужного размера, и консоль показывает мне эту ошибку, что это не так:

2016-07-07 13:12:44.652 TestApp[12517:197564] 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:0x7f84297c21d0 V:[_UILayoutGuide:0x7f84295427b0(0)]>",
    "<_UILayoutSupportConstraint:0x7f84297c3af0 V:|-(0)-[_UILayoutGuide:0x7f84295427b0]   (Names: '|':UIView:0x7f84295e36b0 )>",
    "<NSLayoutConstraint:0x7f8429719520 V:[_UILayoutGuide:0x7f84295427b0]-(5)-[UIImageView:0x7f84297789e0]>",
    "<SnapKit.LayoutConstraint:0x7f8429792d10@/Users/usuario/Swift/TestApp/TestAppV1/TestViewController.swift#62 UIImageView:0x7f84297789e0.centerY == UIView:0x7f84295e36b0.centerY>",
    "<SnapKit.LayoutConstraint:0x7f84297119d0@/Users/usuario/Swift/TestApp/TestAppV1/TestViewController.swift#62 UIImageView:0x7f84297789e0.height == 50.0>",
    "<NSLayoutConstraint:0x7f84295f9480 'UIView-Encapsulated-Layout-Height' V:[UIView:0x7f84295e36b0(568)]>"
)

Will attempt to recover by breaking constraint 
<SnapKit.LayoutConstraint:0x7f84297119d0@/Users/usuario/Swift/TestApp/TestAppV1/TestViewController.swift#62 UIImageView:0x7f84297789e0.height == 50.0>

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.

Любое возможное решение?

Я использую другую библиотеку для ограничений ??

Благодарю вас!


person Alberto Mier    schedule 07.07.2016    source источник


Ответы (1)


Я предполагаю, что imagenPrincipal - это ваше представление изображения, которое позже можно увидеть в этих ограничениях:

 "<NSLayoutConstraint:0x7f8429719520 V:[_UILayoutGuide:0x7f84295427b0]-(5)-[UIImageView:0x7f84297789e0]>",
 "<SnapKit.LayoutConstraint:0x7f8429792d10@/Users/usuario/Swift/TestApp/TestAppV1/TestViewController.swift#62 UIImageView:0x7f84297789e0.centerY == UIView:0x7f84295e36b0.centerY>",
 "<SnapKit.LayoutConstraint:0x7f84297119d0@/Users/usuario/Swift/TestApp/TestAppV1/TestViewController.swift#62 UIImageView:0x7f84297789e0.height == 50.0>",

Если я правильно понял, установите верхнюю часть изображения в верхнюю направляющую макета со смещением на 5 пунктов, затем вы установите centerY в центр представления, а затем установите высоту изображения на 50. Я думая, что вы должны выбрать один из них, либо установите центр Y, либо смещение от верхней направляющей макета, и все будет готово.

person lawicko    schedule 07.07.2016