I need to implement UIScrollView in my app using constraintsWithVisualFormat possible that someone would guide me with some code . Thank You!
import UIKit
class ViewController: UIViewController, UIScrollViewDelegate{
var scrollView: UIScrollView!
var containerView = UIView()
//FUNCION PARA PERMITIR COLORES HEXĂDECIMALES
func uicolorFromHex(rgbValue:UInt32)->UIColor{
let red = CGFloat((rgbValue & 0xFF0000) >> 16)/256.0;
let green = CGFloat((rgbValue & 0xFF00) >> 8)/256.0;
let blue = CGFloat(rgbValue & 0xFF)/256.0;
return UIColor(red:red, green:green, blue:blue, alpha:1.0);
}
//***
override func viewDidLoad() {
super.viewDidLoad()
self.scrollView = UIScrollView()
self.scrollView.delegate = self
containerView = UIView()
containerView.backgroundColor = uicolorFromHex(0x0099FF);
containerView.setTranslatesAutoresizingMaskIntoConstraints(false);
scrollView.addSubview(containerView)
view.addSubview(scrollView)
//*** DICCIONARIO
let viewsDictionary = ["scrollView":scrollView
,"containerView":containerView]
let view_constraint_H:NSArray = NSLayoutConstraint.constraintsWithVisualFormat("H:|-0-[scrollView]-0-|",
options: NSLayoutFormatOptions(0),
metrics: nil,
views: viewsDictionary)
let view_constraint_V:NSArray = NSLayoutConstraint.constraintsWithVisualFormat("V:|-0-[scrollView]-0-|",
options: NSLayoutFormatOptions(0),
metrics: nil,
views: viewsDictionary)
view.addConstraints(view_constraint_H as [AnyObject])
view.addConstraints(view_constraint_V as [AnyObject])
let view_constraintContainer_H:NSArray = NSLayoutConstraint.constraintsWithVisualFormat("H:|-0-[containerView]-0-|",
options: NSLayoutFormatOptions(0),
metrics: nil,
views: viewsDictionary)
let view_constraintContainer_V:NSArray = NSLayoutConstraint.constraintsWithVisualFormat("V:|-0-[containerView]-0-|",
options: NSLayoutFormatOptions(0),
metrics: nil,
views: viewsDictionary)
scrollView.addConstraints(view_constraintContainer_H as [AnyObject])
scrollView.addConstraints(view_constraintContainer_V as [AnyObject])
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
error:
2015-08-04 22:26:05.693 dsds[2017:56799] 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:0x7a7cfc00 H:|-(0)-[UIScrollView:0x7c188200] (Names: '|':UIView:0x7a8499d0 )>", "<NSLayoutConstraint:0x7a7cfe50 H:[UIScrollView:0x7c188200]-(0)-| (Names: '|':UIView:0x7a8499d0 )>", "<NSAutoresizingMaskLayoutConstraint:0x7a7df310 h=--& v=--& H:[UIScrollView:0x7c188200(0)]>", "<NSLayoutConstraint:0x7a7d04e0 'UIView-Encapsulated-Layout-Width' H:[UIView:0x7a8499d0(320)]>" )Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7a7cfe50 H:[UIScrollView:0x7c188200]-(0)-| (Names: '|':UIView:0x7a8499d0 )>Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in may also be helpful. 2015-08-04 22:26:05.695
dsds[2017:56799] 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:0x7a7cfa00 V:|-(0)-[UIScrollView:0x7c188200] (Names: '|':UIView:0x7a8499d0 )>", "<NSLayoutConstraint:0x7a7d0160 V:[UIScrollView:0x7c188200]-(0)-| (Names: '|':UIView:0x7a8499d0 )>", "<NSAutoresizingMaskLayoutConstraint:0x7a7df370 h=--& v=--& V:[UIScrollView:0x7c188200(0)]>", "<NSLayoutConstraint:0x7a7df920 'UIView-Encapsulated-Layout-Height' V:[UIView:0x7a8499d0(568)]>" )Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7a7d0160 V:[UIScrollView:0x7c188200]-(0)-| (Names: '|':UIView:0x7a8499d0 )>Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in may also be helpful. Message from debugger: Terminated due to signal 15
help me!!!! thanks!!!