mardi 4 août 2015

How to implement a UIScrollView using Vertical constraintsWithVisualFormat (SWIFT)

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) ( "", "", "", "" )

Will attempt to recover by breaking constraint

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) ( "", "", "", "" )

Will attempt to recover by breaking constraint

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!!!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire