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
}
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.