Reputation: 69
I am trying to use CGRect.insetBy( dx : ... , dy : ...)
but the code gives me an error which can't be solved at all.
func scaleRect (rect: CGRect , xScale : CGFloat, yScale : CGFloat , offset : CGPoint) -> (CGRect){
let width = rect.width
let height = rect.height
let scaleUp : CGFloat = 2.0
var newWidth = sqrt(width * width * scaleUp)
var newHeight = sqrt(height * height * scaleUp)
var newRect = rect.insetBy(dx: (width - newWidth)/2, dy: (height - newHeight)/2)
// error here *** Value of type '(CGFloat, CGFloat) -> CGRect' has no member 'origin'
var resultRect = CGRect(x: newRect.origin.x, y: newRect.origin.y, width: newRect.size.width, height: newRect.size.height)
resultRect = CGRect.offsetBy(resultRect, offset.x , offset.y)
return resultRect
}
Upvotes: 0
Views: 3089
Reputation: 6555
You should use offsetBy
like this according to Swift,
let rect = resultRect.offsetBy(dx: offset.x, dy: offset.y)
Learn more about insetBy and offsetBy and CGGeometry
Upvotes: 2