ios - '(CGFloat, CGFloat) -> CGRect' 类型的值没有成员'origin'
问题描述
我正在尝试使用CGRect.insetBy( dx : ... , dy : ...)
,但代码给了我一个根本无法解决的错误。
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
}
解决方案
offsetBy
根据 Swift,你应该像这样使用,
let rect = resultRect.offsetBy(dx: offset.x, dy: offset.y)
推荐阅读
- python - 添加功能以在我的 Discord 机器人 [Python] 中使用关键字在 Youtube 上进行搜索
- node.js - 如何使用带有 mongoose@6.0.5 和 Nodejs 的 SSL 证书连接到 Mongodb?
- javascript - 按字母数字顺序排列数组并带有条件
- laravel - Laravel用camelCase创建方法
- ssh - 在两个远程主机之间传输文件,在本地拥有授权密钥?
- node.js - 如何从我的数据库查询中获取结果?
- flutter - 在flutter中覆盖提升按钮.icon内的标签和图标颜色?
- python - 在 S3 中获取最新上传文件的最简单方法是什么(当其他现有文件被覆盖时)-Python
- html - 锚标记不更改 URL
- javascript - NPM 包是否有“手册页”或 `--help`