lib/sugarcube-uikit/uiview.rb in sugarcube-1.1.0 vs lib/sugarcube-uikit/uiview.rb in sugarcube-1.3.0
- old
+ new
@@ -8,16 +8,16 @@
end
def attr_updates(*attrs)
attr_accessor(*attrs)
attrs.each do |attr|
- define_method("#{attr}=") { |value|
+ define_method("#{attr}=") do |value|
if instance_variable_get("@#{attr}") != value
setNeedsDisplay
end
instance_variable_set("@#{attr}", value)
- }
+ end
end
end
end
@@ -78,11 +78,11 @@
def uiimage(use_content_size=false)
scale = UIScreen.mainScreen.scale
if use_content_size
UIGraphicsBeginImageContextWithOptions(contentSize, false, scale)
context = UIGraphicsGetCurrentContext()
- subviews.each do |subview|
+ self.subviews.each do |subview|
CGContextSaveGState(context)
CGContextTranslateCTM(context, subview.frame.origin.x, subview.frame.origin.y)
subview.layer.renderInContext(context)
CGContextRestoreGState(context)
end
@@ -97,14 +97,84 @@
return image
end
# Returns the receiver's bounds in the coordinate system of `destination`
def convert_bounds(destination)
- self.convertRect(self.bounds, toView:destination)
+ message = "The (ambiguously named) `convert_bounds` method has been deprecated, use `convert_frame_to` (or `convert_frame_from`)"
+ if defined?(SugarCube::Legacy)
+ SugarCube::Legacy.log(message)
+ else
+ NSLog(message)
+ end
+ return convert_frame_to(destination)
end
+ def convert_frame_to(destination)
+ return self.convertRect(CGRectMake(0, 0, self.frame.size.width, self.frame.size.height), toView:destination)
+ end
+
+ def convert_frame_from(source)
+ return self.convertRect(CGRectMake(0, 0, source.frame.size.width, source.frame.size.height), fromView:source)
+ end
+
# Returns the receiver's bounds in the coordinate system of `destination`
def convert_origin(destination)
- self.convertPoint([0, 0], toView:destination)
+ message = "The (ambiguously named) `convert_origin` method has been deprecated, use `convert_origin_to` (or `convert_origin_from`)"
+ if defined?(SugarCube::Legacy)
+ SugarCube::Legacy.log(message)
+ else
+ NSLog(message)
+ end
+ return self.convert_origin_to(destination)
+ end
+
+ def convert_origin_to(destination)
+ return self.convertPoint([0, 0], toView:destination)
+ end
+
+ def convert_origin_from(source)
+ return self.convertPoint([0, 0], fromView:source)
+ end
+
+ # Easily get and set a UIView's frame properties
+
+ def x
+ self.frame.origin.x
+ end
+
+ def setX(newX)
+ newFrame = self.frame
+ newFrame.origin.x = newX
+ self.frame = newFrame
+ end
+
+ def y
+ self.frame.origin.y
+ end
+
+ def setY(newY)
+ newFrame = self.frame
+ newFrame.origin.y = newY
+ self.frame = newFrame
+ end
+
+ def height
+ self.frame.size.height
+ end
+
+ def setHeight(newHeight)
+ newFrame = self.frame
+ newFrame.size.height = newHeight
+ self.frame = newFrame
+ end
+
+ def width
+ self.frame.size.width
+ end
+
+ def setWidth(newWidth)
+ newFrame = self.frame
+ newFrame.size.width = newWidth
+ self.frame = newFrame
end
end