class MotionKit::UIViewHelpers
Public Instance Methods
_calculate_frame(f, from: from_view, relative_to: point)
click to toggle source
# File lib/motion-kit-ios/helpers/uiview_frame_helpers.rb, line 92 def _calculate_frame(f, from: from_view, relative_to: point) if from_view.is_a?(Symbol) from_view = self.get_view(from_view) end from_view_size = from_view.frame.size o = from_view.convertPoint([0, 0], toView: target.superview) calculate_view = UIView.alloc.initWithFrame([[0, 0], target.frame.size]) if f.is_a?(Hash) f = f.merge(relative: true) end f = MotionKit.calculate(calculate_view, :frame, f, target.superview) f.origin.x += o.x f.origin.y += o.y case point[:x] when :min, :reset # pass when :mid f.origin.x += (from_view_size.width - f.size.width) / 2.0 when :max f.origin.x += from_view_size.width - f.size.width when :before f.origin.x -= f.size.width when :after f.origin.x += from_view_size.width else f.origin.x += point[:x] end case point[:y] when :min, :reset # pass when :mid f.origin.y += (from_view_size.height - f.size.height) / 2.0 when :max f.origin.y += from_view_size.height - f.size.height when :above f.origin.y -= f.size.height when :below f.origin.y += from_view_size.height else f.origin.y += point[:y] end return f end
above(from_view, f={})
click to toggle source
The first arg can be a view or a frame @example
frame above(view, [[0, 0], [100, 20]]) frame above(:view, x: 0, y: 0, width: 100, height: 20) frame above(:view, down: 0, right: 0, width: 100, height: 20)
# File lib/motion-kit-ios/helpers/uiview_frame_helpers.rb, line 273 def above(from_view, f={}) _calculate_frame(f, from: from_view, relative_to: { x: :reset, y: :above }) end
after(from_view, f={})
click to toggle source
The first arg can be a view or a frame @example
frame after(view, [[0, 0], [100, 20]]) frame after(:view, x: 0, y: 0, width: 100, height: 20) frame after(:view, down: 0, right: 0, width: 100, height: 20)
# File lib/motion-kit-ios/helpers/uiview_frame_helpers.rb, line 301 def after(from_view, f={}) _calculate_frame(f, from: from_view, relative_to: { x: :after, y: :reset }) end
Also aliased as: right_of, right_of
autoresizing_mask(*values)
click to toggle source
# File lib/motion-kit-ios/helpers/uiview_autoresizing_helpers.rb, line 5 def autoresizing_mask(*values) value = 0 values.each do |mask| case mask when :flexible_left value |= UIViewAutoresizingFlexibleLeftMargin when :flexible_width value |= UIViewAutoresizingFlexibleWidth when :flexible_right value |= UIViewAutoresizingFlexibleRightMargin when :flexible_top value |= UIViewAutoresizingFlexibleTopMargin when :flexible_height value |= UIViewAutoresizingFlexibleHeight when :flexible_bottom value |= UIViewAutoresizingFlexibleBottomMargin when :rigid_left value ^= UIViewAutoresizingFlexibleLeftMargin when :rigid_width value ^= UIViewAutoresizingFlexibleWidth when :rigid_right value ^= UIViewAutoresizingFlexibleRightMargin when :rigid_top value ^= UIViewAutoresizingFlexibleTopMargin when :rigid_height value ^= UIViewAutoresizingFlexibleHeight when :rigid_bottom value ^= UIViewAutoresizingFlexibleBottomMargin when :fill value |= UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight when :fill_top value |= UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin when :fill_bottom value |= UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin when :fill_width value |= UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin when :fill_left value |= UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleRightMargin when :fill_right value |= UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleLeftMargin when :fill_height value |= UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleRightMargin when :pin_to_top_left value |= UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin when :pin_to_top value |= UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin when :pin_to_top_right value |= UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin when :pin_to_left value |= UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleRightMargin when :pin_to_center, :pin_to_middle value |= UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin when :pin_to_right value |= UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin when :pin_to_bottom_left value |= UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin when :pin_to_bottom value |= UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin when :pin_to_bottom_right value |= UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin else value |= mask end end target.autoresizingMask = value value end
Also aliased as: autoresizingMask, autoresizingMask
before(from_view, f={})
click to toggle source
The first arg can be a view or a frame @example
frame before(view, [[0, 0], [100, 20]]) frame before(:view, x: 0, y: 0, width: 100, height: 20) frame before(:view, down: 0, right: 0, width: 100, height: 20)
# File lib/motion-kit-ios/helpers/uiview_frame_helpers.rb, line 291 def before(from_view, f={}) _calculate_frame(f, from: from_view, relative_to: { x: :before, y: :reset }) end
Also aliased as: left_of, left_of
below(from_view, f={})
click to toggle source
The first arg can be a view or a frame @example
frame below(view, [[0, 0], [100, 20]]) frame below(:view, x: 0, y: 0, width: 100, height: 20) frame below(:view, down: 0, right: 0, width: 100, height: 20)
# File lib/motion-kit-ios/helpers/uiview_frame_helpers.rb, line 282 def below(from_view, f={}) _calculate_frame(f, from: from_view, relative_to: { x: :reset, y: :below }) end
bottom(value)
click to toggle source
# File lib/motion-kit-ios/helpers/uiview_frame_helpers.rb, line 36 def bottom(value) f = target.frame f.origin.y = MotionKit.calculate(target, :height, value) - f.size.height target.frame = f return CGRectGetMaxY(f) end
center(value)
click to toggle source
# File lib/motion-kit-ios/helpers/uiview_frame_helpers.rb, line 74 def center(value) target.center = MotionKit.calculate(target, :center, value) return target.center end
Also aliased as: middle, middle
center_x(value)
click to toggle source
# File lib/motion-kit-ios/helpers/uiview_frame_helpers.rb, line 20 def center_x(value) c = target.center c.x = MotionKit.calculate(target, :width, value) target.center = c return CGRectGetMidX(target.frame) end
Also aliased as: middle_x, middle_x
center_y(value)
click to toggle source
# File lib/motion-kit-ios/helpers/uiview_frame_helpers.rb, line 43 def center_y(value) c = target.center c.y = MotionKit.calculate(target, :height, value) target.center = c return CGRectGetMidY(target.frame) end
Also aliased as: middle_y, middle_y
compression_priority(value, for_axis: axis)
click to toggle source
# File lib/motion-kit-ios/helpers/constraints_helpers.rb, line 10 def compression_priority(value, for_axis: axis) content_compression_resistance_priority(value, for_axis: axis) end
constraints(add_to_view=nil, &block)
click to toggle source
# File lib/motion-kit-ios/helpers/uiview_constraints_helpers.rb, line 5 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
content_compression_resistance_priority(value, for_axis: axis)
click to toggle source
# File lib/motion-kit-ios/helpers/constraints_helpers.rb, line 5 def content_compression_resistance_priority(value, for_axis: axis) axis = Constraint.axis_lookup(axis) target.setContentCompressionResistancePriority(value, forAxis: axis) end
content_hugging_priority(value, for_axis: axis)
click to toggle source
# File lib/motion-kit-ios/helpers/constraints_helpers.rb, line 14 def content_hugging_priority(value, for_axis: axis) axis = Constraint.axis_lookup(axis) target.setContentHuggingPriority(value, forAxis: axis) end
frame(value)
click to toggle source
# File lib/motion-kit-ios/helpers/uiview_frame_helpers.rb, line 87 def frame(value) target.frame = MotionKit.calculate(target, :frame, value) return target.frame end
from_bottom(from_view=nil, f=nil)
click to toggle source
The first arg can be a view or a frame @example
frame from_bottom(width: 80, height: 22) frame from_bottom(another_view, width: 80, height: 22)
# File lib/motion-kit-ios/helpers/uiview_frame_helpers.rb, line 244 def from_bottom(from_view=nil, f=nil) if from_view.is_a?(Hash) f = from_view from_view = nil end f ||= {} from_view ||= target.superview _calculate_frame(f, from: from_view, relative_to: { x: :mid, y: :max }) end
from_bottom_left(from_view=nil, f=nil)
click to toggle source
The first arg can be a view or a frame @example
frame from_bottom_left(width: 80, height: 22) frame from_bottom_left(another_view, width: 80, height: 22)
# File lib/motion-kit-ios/helpers/uiview_frame_helpers.rb, line 230 def from_bottom_left(from_view=nil, f=nil) if from_view.is_a?(Hash) f = from_view from_view = nil end f ||= {} from_view ||= target.superview _calculate_frame(f, from: from_view, relative_to: { x: :min, y: :max }) end
from_bottom_right(from_view=nil, f=nil)
click to toggle source
The first arg can be a view or a frame @example
frame from_bottom_right(width: 80, height: 22) frame from_bottom_right(another_view, width: 80, height: 22)
# File lib/motion-kit-ios/helpers/uiview_frame_helpers.rb, line 258 def from_bottom_right(from_view=nil, f=nil) if from_view.is_a?(Hash) f = from_view from_view = nil end f ||= {} from_view ||= target.superview _calculate_frame(f, from: from_view, relative_to: { x: :max, y: :max }) end
from_center(from_view=nil, f=nil)
click to toggle source
The first arg can be a view or a frame @example
frame from_center(width: 80, height: 22) frame from_center(another_view, width: 80, height: 22)
# File lib/motion-kit-ios/helpers/uiview_frame_helpers.rb, line 202 def from_center(from_view=nil, f=nil) if from_view.is_a?(Hash) f = from_view from_view = nil end f ||= {} from_view ||= target.superview _calculate_frame(f, from: from_view, relative_to: { x: :mid, y: :mid }) end
from_left(from_view=nil, f=nil)
click to toggle source
The first arg can be a view or a frame @example
frame from_left(width: 80, height: 22) frame from_left(another_view, width: 80, height: 22)
# File lib/motion-kit-ios/helpers/uiview_frame_helpers.rb, line 188 def from_left(from_view=nil, f=nil) if from_view.is_a?(Hash) f = from_view from_view = nil end f ||= {} from_view ||= target.superview _calculate_frame(f, from: from_view, relative_to: { x: :min, y: :mid }) end
from_right(from_view=nil, f=nil)
click to toggle source
The first arg can be a view or a frame @example
frame from_right(width: 80, height: 22) frame from_right(another_view, width: 80, height: 22)
# File lib/motion-kit-ios/helpers/uiview_frame_helpers.rb, line 216 def from_right(from_view=nil, f=nil) if from_view.is_a?(Hash) f = from_view from_view = nil end f ||= {} from_view ||= target.superview _calculate_frame(f, from: from_view, relative_to: { x: :max, y: :mid }) end
from_top(from_view=nil, f=nil)
click to toggle source
The first arg can be a view or a frame @example
frame from_top(width: 80, height: 22) frame from_top(another_view, width: 80, height: 22)
# File lib/motion-kit-ios/helpers/uiview_frame_helpers.rb, line 160 def from_top(from_view=nil, f=nil) if from_view.is_a?(Hash) f = from_view from_view = nil end f ||= {} from_view ||= target.superview _calculate_frame(f, from: from_view, relative_to: { x: :mid, y: :min }) end
from_top_left(from_view=nil, f=nil)
click to toggle source
The first arg can be a view or a frame @example
frame from_top_left(width: 80, height: 22) frame from_top_left(another_view, width: 80, height: 22)
# File lib/motion-kit-ios/helpers/uiview_frame_helpers.rb, line 146 def from_top_left(from_view=nil, f=nil) if from_view.is_a?(Hash) f = from_view from_view = nil end f ||= {} from_view ||= target.superview _calculate_frame(f, from: from_view, relative_to: { x: :min, y: :min }) end
from_top_right(from_view=nil, f=nil)
click to toggle source
The first arg can be a view or a frame @example
frame from_top_right(width: 80, height: 22) frame from_top_right(another_view, width: 80, height: 22)
# File lib/motion-kit-ios/helpers/uiview_frame_helpers.rb, line 174 def from_top_right(from_view=nil, f=nil) if from_view.is_a?(Hash) f = from_view from_view = nil end f ||= {} from_view ||= target.superview _calculate_frame(f, from: from_view, relative_to: { x: :max, y: :min }) end
gradient(&block)
click to toggle source
gradient colors:
# File lib/motion-kit-ios/helpers/uiview_gradient_helpers.rb, line 6 def gradient(&block) gradient_layer = target.motion_kit_meta[:motionkit_gradient_layer] || begin gradient_layer = CAGradientLayer.layer gradient_layer.frame = CGRect.new([0, 0], target.frame.size) target.layer.insertSublayer(gradient_layer, atIndex:0) target.motion_kit_meta[:motionkit_gradient_layer] = gradient_layer gradient_layer end context(gradient_layer, &block) gradient_layer end
height(value)
click to toggle source
# File lib/motion-kit-ios/helpers/uiview_frame_helpers.rb, line 59 def height(value) f = target.frame f.size.height = MotionKit.calculate(target, :height, value) target.frame = f return CGRectGetHeight(f) end
Also aliased as: h, h
hugging_priority(value, for_axis: axis)
click to toggle source
# File lib/motion-kit-ios/helpers/constraints_helpers.rb, line 19 def hugging_priority(value, for_axis: axis) content_hugging_priority(value, for_axis: axis) end
origin(value)
click to toggle source
# File lib/motion-kit-ios/helpers/uiview_frame_helpers.rb, line 67 def origin(value) f = target.frame f.origin = MotionKit.calculate(target, :origin, value) target.frame = f return target.frame.origin end
relative_to(from_view, f)
click to toggle source
The first arg must be a view @example
frame relative_to(view, [[0, 0], [100, 20]]) frame relative_to(:view, x: 0, y: 0, width: 100, height: 20) frame relative_to(:view, down: 0, right: 0, width: 100, height: 20)
# File lib/motion-kit-ios/helpers/uiview_frame_helpers.rb, line 311 def relative_to(from_view, f) _calculate_frame(f, from: from_view, relative_to: { x: :reset, y: :reset }) end
right(value)
click to toggle source
# File lib/motion-kit-ios/helpers/uiview_frame_helpers.rb, line 13 def right(value) f = target.frame f.origin.x = MotionKit.calculate(target, :width, value) - f.size.width target.frame = f return CGRectGetMaxX(f) end
size(value)
click to toggle source
# File lib/motion-kit-ios/helpers/uiview_frame_helpers.rb, line 80 def size(value) f = target.frame f.size = MotionKit.calculate(target, :size, value) target.frame = f return target.frame.size end
width(value)
click to toggle source
# File lib/motion-kit-ios/helpers/uiview_frame_helpers.rb, line 51 def width(value) f = target.frame f.size.width = MotionKit.calculate(target, :width, value) target.frame = f return CGRectGetWidth(f) end
Also aliased as: w, w
x(value)
click to toggle source
# File lib/motion-kit-ios/helpers/uiview_frame_helpers.rb, line 5 def x(value) f = target.frame f.origin.x = MotionKit.calculate(target, :width, value) target.frame = f return CGRectGetMinX(f) end
Also aliased as: left, left
y(value)
click to toggle source
# File lib/motion-kit-ios/helpers/uiview_frame_helpers.rb, line 28 def y(value) f = target.frame f.origin.y = MotionKit.calculate(target, :height, value) target.frame = f return CGRectGetMinY(f) end
Also aliased as: top, top