Upgrade to Pro — share decks privately, control downloads, hide ads and more …

制約を使ってViewを動かす

taminif
March 12, 2017

 制約を使ってViewを動かす

taminif

March 12, 2017
Tweet

More Decks by taminif

Other Decks in Programming

Transcript

  1. ੍໿ͱ͸ • Auto LayoutΛߏ੒͢ΔͨΊͷʮ৚݅ʯ • ཁૉͷҐஔ = ׂ߹ * ର৅ཁૉͷҐஔ

    + ڑ཭
 Ͱߏ੒͞ΕΔ • ʮԣ෯ͷத৺ʯʮॎ෯ͷத৺ʯ΋ઃఆՄೳ
  2. ίʔυྫ class ViewController: UIViewController { @IBOutlet var testView: UIView! @IBOutlet

    var testViewLeadingConstraint: NSLayoutConstraint! @IBAction func buttonTouchDown(_ sender: Any) { self.testViewLeadingConstraint.constant = self.testView.frame.width } }
  3. animate௥Ճ class ViewController: UIViewController { @IBOutlet var testView: UIView! @IBOutlet

    var testViewLeadingConstraint: NSLayoutConstraint! @IBAction func buttonTouchDown(_ sender: Any) { UIView.animate(withDuration: 3.0, animations: { self.testViewLeadingConstraint.constant = self.testView.frame.width }) } }
  4. Ξχϝʔγϣϯ͢Δํ๏ class ViewController: UIViewController { @IBOutlet var testView: UIView! @IBOutlet

    var testViewLeadingConstraint: NSLayoutConstraint! @IBAction func buttonTouchDown(_ sender: Any) { self.testViewLeadingConstraint.constant = self.testView.frame.width UIView.animate(withDuration: 3.0, animations: { self.view.layoutIfNeeded() }) } } ->΄ͱΜͲͷαΠτͰಉ͡಺༰͕ग़ͯ͘Δ
  5. Ξχϝʔγϣϯ͢Δ৚݅ View Programming Guide for iOSΑΓ • UIViewΛ࢖༻ • frame,

    boundsͳͲݶΒΕ߲ͨ໨ͷΈՄೳ • ConstraintͰઃఆ੍ͨ͠໿͸LayoutΛߋ৽͢ Δ·Ͱมߋ͞Εͳ͍ • layoutIfNeededΛݺͿ͜ͱͰ഑ஔ͕มΘΔͨ ΊΞχϝʔγϣϯ͞ΕΔʢਪଌʣ