module Loco::Resizable

Attributes

bottom[RW]

The position of the bottom edge, relative to the superview’s bottom edge. @return [Integer]

height[RW]

The height of the view. @return [Integer]

left[RW]

The position of the left edge, relative to the superview’s left edge. @return [Integer]

parentView[RW]
parent_view[RW]
right[RW]

The position of the right edge, relative to the superview’s right edge. @return [Integer]

top[RW]

The position of the top edge, relative to the superview’s top edge. @return [Integer]

width[RW]

The width of the view. @return [Integer]

Public Class Methods

included(base) click to toggle source
# File lib/motion-loco/resizable.rb, line 305
def self.included(base)
  base.extend(Observable::ClassMethods)
end

Public Instance Methods

bottom=(bottom) click to toggle source
Calls superclass method
# File lib/motion-loco/resizable.rb, line 28
def bottom=(bottom)
  super
  refresh_layout
end
height=(height) click to toggle source
Calls superclass method
# File lib/motion-loco/resizable.rb, line 43
def height=(height)
  super
  refresh_layout
end
initWithFrame(properties={}) click to toggle source

Create new instance from a hash of properties with values. @param [Object] frame The CGRect or a Hash of properties.

Calls superclass method
# File lib/motion-loco/resizable.rb, line 113
def initWithFrame(properties={})
  if properties.is_a? Hash
    # Set the initial property values from the given hash
    super(CGRect.new)
    initialize_bindings
    set_properties(properties)
  else
    super(properties)
  end
  view_setup
  
  self
end
left=(left) click to toggle source
Calls superclass method
# File lib/motion-loco/resizable.rb, line 59
def left=(left)
  super
  refresh_layout
end
parent_view=(view) click to toggle source

Required for bindings to work for both styles

Calls superclass method
# File lib/motion-loco/resizable.rb, line 8
def parent_view=(view)
  self.parentView = view
  super
end
refreshLayout(superview=nil)
Alias for: refresh_layout
refresh_layout(superview=nil) click to toggle source

Refresh the layout based on bottom, left, right, top, and superview. @param [UIView] superview

# File lib/motion-loco/resizable.rb, line 129
def refresh_layout(superview=nil)
  # The view can't be positioned without being added to the superview first.
  superview ||= self.superview
  return if superview.nil?

  # Determine the original size, position, and autoresizing mask that should be used.
  if self.top && self.bottom
    if self.left && self.right
      # FW, FH
      @origin_x     = self.left
      @origin_y     = self.top
      @size_height  = superview.bounds.size.height - self.top - self.bottom
      @size_width   = superview.bounds.size.width - self.left - self.right
      @autoresizing = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight
    elsif self.left && self.width
      # FH, FRM
      @origin_x     = self.left
      @origin_y     = self.top
      @size_height  = superview.bounds.size.height - self.top - self.bottom
      @size_width   = self.width
      @autoresizing = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleRightMargin
    elsif self.right && self.width
      # FH, FLM
      @origin_x     = superview.bounds.size.width - self.width - self.right
      @origin_y     = self.top
      @size_height  = superview.bounds.size.height - self.top - self.bottom
      @size_width   = self.width
      @autoresizing = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleLeftMargin
    elsif self.width
      # FH, FLM, FRM
      @origin_x     = (superview.bounds.size.width - self.width) / 2
      @origin_y     = self.top
      @size_height  = superview.bounds.size.height - self.top - self.bottom
      @size_width   = self.width
      @autoresizing = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin
    else
      # Needs More Params
      NSLog('%@<Loco::UI::View> Not enough params to position and size the view.', self.class)
    end
  elsif self.top
    if self.left && self.right && self.height
      # FW, FBM
      @origin_x     = self.left
      @origin_y     = self.top
      @size_height  = self.height
      @size_width   = superview.bounds.size.width - self.left - self.right
      @autoresizing = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin
    elsif self.left && self.height && self.width
      # FBM, FRM
      @origin_x     = self.left
      @origin_y     = self.top
      @size_height  = self.height
      @size_width   = self.width
      @autoresizing = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleRightMargin
    elsif self.right && self.height && self.width
      # FBM, FLM
      @origin_x     = superview.bounds.size.width - self.width - self.right
      @origin_y     = self.top
      @size_height  = self.height
      @size_width   = self.width
      @autoresizing = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin
    elsif self.height && self.width
      # FLM, FRM, FBM
      @origin_x     = (superview.bounds.size.width - self.width) / 2
      @origin_y     = self.top
      @size_height  = self.height
      @size_width   = self.width
      @autoresizing = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin |UIViewAutoresizingFlexibleBottomMargin
    else
      # Needs More Params
      NSLog('%@<Loco::UI::View> Not enough params to position and size the view.', self.class)
    end
  elsif self.bottom
    if self.left && self.right && self.height
      # FW, FTM
      @origin_x     = self.left
      @origin_y     = superview.bounds.size.height - self.height - self.bottom
      @size_height  = self.height
      @size_width   = superview.bounds.size.width - self.left - self.right
      @autoresizing = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin
    elsif self.left && self.height && self.width
      # FTM, FRM
      @origin_x     = self.left
      @origin_y     = superview.bounds.size.height - self.height - self.bottom
      @size_height  = self.height
      @size_width   = self.width
      @autoresizing = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleRightMargin
    elsif self.right && self.height && self.width
      # FTM, FLM
      @origin_x     = superview.bounds.size.width - self.width - self.right
      @origin_y     = superview.bounds.size.height - self.height - self.bottom
      @size_height  = self.height
      @size_width   = self.width
      @autoresizing = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin
    elsif self.height && self.width
      # FLM, FRM, FTM
      @origin_x     = (superview.bounds.size.width - self.width) / 2
      @origin_y     = superview.bounds.size.height - self.height - self.bottom
      @size_height  = self.height
      @size_width   = self.width
      @autoresizing = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin |UIViewAutoresizingFlexibleTopMargin
    else
      # Needs More Params
      NSLog('%@<Loco::UI::View> Not enough params to position and size the view.', self.class)
    end
  elsif self.left && self.right && self.height
    # FW, FTM, FBM
    @origin_x     = self.left
    @origin_y     = (superview.bounds.size.height - self.height) / 2
    @size_height  = self.height
    @size_width   = superview.bounds.size.width - self.left - self.right
    @autoresizing = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin
  elsif self.width && self.height
    if self.left
      # FTM, FBM, FRM
      @origin_x     = self.left
      @origin_y     = (superview.bounds.size.height - self.height) / 2
      @size_height  = self.height
      @size_width   = self.width
      @autoresizing = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleRightMargin
    elsif self.right
      # FTM, FBM, FLM
      @origin_x     = superview.bounds.size.width - self.width - self.right
      @origin_y     = (superview.bounds.size.height - self.height) / 2
      @size_height  = self.height
      @size_width   = self.width
      @autoresizing = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin
    else
      # FTM, FBM, FLM, FRM
      @origin_x     = (superview.bounds.size.width - self.width) / 2
      @origin_y     = (superview.bounds.size.height - self.height) / 2
      @size_height  = self.height
      @size_width   = self.width
      @autoresizing = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin
    end
  else
    # Needs More Params
    NSLog('%@<Loco::UI::View> Not enough params to position and size the view.', self.class)
  end
  
  # Warn of any possible conflicts
  if self.top && self.bottom && self.height
    NSLog('%@<Loco::UI::View> `top`, `bottom`, and `height` may conflict with each other. Only two of the three should be set.', self.class)
    NSLog('%@<Loco::UI::View> top: %@, bottom: %@, height: %@', self.class, self.top, self.bottom, self.height)
  end
  if self.left && self.right && self.width
    NSLog('%@<Loco::UI::View> `left`, `right`, and `width` may conflict with each other. Only two of the three should be set.', self.class)
    NSLog('%@<Loco::UI::View> left: %@, right: %@, width: %@', self.class, self.left, self.right, self.width)
  end
  
  if @origin_x && @origin_y && @size_width && @size_height && @autoresizing
    self.frame = [[@origin_x, @origin_y], [@size_width, @size_height]]
    self.autoresizingMask = @autoresizing
  end
  
  # Update the subviews
  self.subviews.each do |view|
    view.refresh_layout(self) if view.is_a? Resizable
  end
end
Also aliased as: refreshLayout
right=(right) click to toggle source
Calls superclass method
# File lib/motion-loco/resizable.rb, line 75
def right=(right)
  super
  refresh_layout
end
top=(top) click to toggle source
Calls superclass method
# File lib/motion-loco/resizable.rb, line 91
def top=(top)
  super
  refresh_layout
end
viewSetup() click to toggle source
# File lib/motion-loco/resizable.rb, line 295
def viewSetup
  # Override #view_setup or #viewSetup to customize the view
end
view_setup() click to toggle source
# File lib/motion-loco/resizable.rb, line 291
def view_setup
  viewSetup
end
width=(width) click to toggle source
Calls superclass method
# File lib/motion-loco/resizable.rb, line 106
def width=(width)
  super
  refresh_layout
end
willMoveToSuperview(superview) click to toggle source

Fires when the superview changes.

# File lib/motion-loco/resizable.rb, line 300
def willMoveToSuperview(superview)
  self.parent_view = superview
  refresh_layout(superview)
end