lib/sugarcube-uikit/uiview.rb in sugarcube-1.0.3 vs lib/sugarcube-uikit/uiview.rb in sugarcube-1.0.4
- old
+ new
@@ -74,27 +74,37 @@
#
# It is guaranteed that `true` and `:all` will always have this behavior. In
# the future, if this argument becomes something that accepts multiple values,
# those two are sacred.
def uiimage(use_content_size=false)
- scale = UIScreen.mainScreen.scale
- if use_content_size
- UIGraphicsBeginImageContextWithOptions(contentSize, false, scale)
- context = UIGraphicsGetCurrentContext()
- subviews.each do |subview|
- CGContextSaveGState(context)
- CGContextTranslateCTM(context, subview.frame.origin.x, subview.frame.origin.y)
- subview.layer.renderInContext(context)
- CGContextRestoreGState(context)
- end
- image = UIGraphicsGetImageFromCurrentImageContext()
- UIGraphicsEndImageContext()
- else
- UIGraphicsBeginImageContextWithOptions(bounds.size, false, scale)
- layer.renderInContext(UIGraphicsGetCurrentContext())
- image = UIGraphicsGetImageFromCurrentImageContext()
- UIGraphicsEndImageContext()
- end
- return image
- end
+ scale = UIScreen.mainScreen.scale
+ if use_content_size
+ UIGraphicsBeginImageContextWithOptions(contentSize, false, scale)
+ context = UIGraphicsGetCurrentContext()
+ subviews.each do |subview|
+ CGContextSaveGState(context)
+ CGContextTranslateCTM(context, subview.frame.origin.x, subview.frame.origin.y)
+ subview.layer.renderInContext(context)
+ CGContextRestoreGState(context)
+ end
+ image = UIGraphicsGetImageFromCurrentImageContext()
+ UIGraphicsEndImageContext()
+ else
+ UIGraphicsBeginImageContextWithOptions(bounds.size, false, scale)
+ layer.renderInContext(UIGraphicsGetCurrentContext())
+ image = UIGraphicsGetImageFromCurrentImageContext()
+ UIGraphicsEndImageContext()
+ end
+ return image
+ end
+
+ # Returns the receiver's bounds in the coordinate system of `destination`
+ def convert_bounds(destination)
+ self.convertRect(self.bounds, toView:destination)
+ end
+
+ # Returns the receiver's bounds in the coordinate system of `destination`
+ def convert_origin(destination)
+ self.convertPoint([0, 0], toView:destination)
+ end
end