Sha256: 0fff5cf2de3a730f18944654f0ee311233b2767eac29c8eb696b3a409b7d2f54

Contents?: true

Size: 941 Bytes

Versions: 21

Compression:

Stored size: 941 Bytes

Contents

# @requires MotionKit::UIViewHelpers
module MotionKit
  class UIViewHelpers

    def constraints(add_to_view=nil, &block)
      add_to_view ||= target
      if add_to_view.is_a?(Symbol)
        add_to_view = self.get_view(add_to_view)
      end
      add_to_view.setTranslatesAutoresizingMaskIntoConstraints(false)

      constraints_target = ConstraintsTarget.new(add_to_view)
      deferred(constraints_target) do
        context(constraints_target, &block)
        constraints_target.apply_all_constraints(self, add_to_view)
      end
    end

  end

  class Layout

    # Ensure we always have a context in this method; makes it easier to define
    # constraints in an `add_constraints` method.
    def constraints(add_to_view=nil, &block)
      if has_context?
        apply(:constraints, add_to_view, &block)
      else
        context(self.view) do
          constraints(add_to_view, &block)
        end
      end
    end

  end
end

Version data entries

21 entries across 15 versions & 1 rubygems

Version Path
motion-kit-0.12.0 lib/motion-kit-ios/layouts/uiview_layout_constraints.rb