Class: MotionKit::Layout

Inherits:
TreeLayout show all
Defined in:
lib/motion-kit-ios/layouts/uiview_layout.rb,
lib/motion-kit-osx/layouts/nsview_layout.rb,
lib/motion-kit-ios/layouts/uiview_layout_constraints.rb,
lib/motion-kit-osx/layouts/nsview_layout_constraints.rb

Direct Known Subclasses

NSViewLayout, UIViewLayout

Instance Attribute Summary

Attributes inherited from BaseLayout

#parent

Instance Method Summary collapse

Methods inherited from TreeLayout

#add, #all, #build, #built?, #call_style_method, #create, #create_default_root_context, #first, #get, #initial, #last, #nth, #reapply, #remove, #root, #view, view

Methods inherited from BaseLayout

#add_deferred_block, #apply, #apply_with_context, #apply_with_target, #context, #deferred, #deferred_blocks, delegate_method_fix, #initialize, #ipad?, #iphone35?, #iphone4?, #iphone?, #method_missing, #orientation?, #retina?, #run_deferred, #set_layout, #target, #v

Methods included from BaseLayoutClassMethods

#layout_for, #memoize, #new_child, #target_klasses, #targets

Constructor Details

This class inherits a constructor from MotionKit::BaseLayout

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class MotionKit::BaseLayout

Instance Method Details

#add_child(subview) ⇒ Object



14
15
16
# File 'lib/motion-kit-ios/layouts/uiview_layout.rb', line 14

def add_child(subview)
  target.addSubview(subview)
end

#constraints(view = nil, &block) ⇒ Object

Ensure we always have a context in this method; makes it easier to define constraints in an ‘add_constraints` method.



25
26
27
28
29
30
31
32
33
# File 'lib/motion-kit-ios/layouts/uiview_layout_constraints.rb', line 25

def constraints(view=nil, &block)
  if @context
    apply(:constraints, view, &block)
  else
    context(self.view) do
      constraints(view, &block)
    end
  end
end

#default_rootObject

platform specific default root view



8
9
10
11
12
# File 'lib/motion-kit-ios/layouts/uiview_layout.rb', line 8

def default_root
  # child Layout classes will return *their* UIView subclass from self.targets
  view_class = self.class.targets || MotionKit.default_view_class
  view_class.alloc.initWithFrame(UIScreen.mainScreen.applicationFrame)
end

#reapply!(root = nil) ⇒ Object

NSViews AND CALayers are updated



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/motion-kit-ios/layouts/uiview_layout.rb', line 23

def reapply!(root=nil)
  if root.is_a?(CALayer)
    @layout_state = :reapply
    MotionKit.find_all_layers(root) do |layer|
      call_style_method(layer, layer.motion_kit_id) if layer.motion_kit_id
    end
    @layout_state = :initial
  else
    root ||= self.view
    reapply!(root.layer)
    super(root)
  end

  return self
end

#remove_child(subview) ⇒ Object



18
19
20
# File 'lib/motion-kit-ios/layouts/uiview_layout.rb', line 18

def remove_child(subview)
  subview.removeFromSuperview
end