iOS convert 方法

2020-09-19  本文已影响0人  gaookey
1
func convert(_ point: CGPoint, to coordinateSpace: UICoordinateSpace) -> CGPoint
open func convert(_ point: CGPoint, to view: UIView?) -> CGPoint
let tempPoint = CGPoint(x: 20, y: 20)
let result = toView.convert(tempPoint, to: fromView)

==

let x = (toView.frame.origin.x + tempPoint.x - fromView.frame.origin.x)
let y = (toView.frame.origin.y + tempPoint.y - fromView.frame.origin.y)
let result = CGPoint(x: x, y: y)
2
func convert(_ point: CGPoint, from coordinateSpace: UICoordinateSpace) -> CGPoint
open func convert(_ point: CGPoint, from view: UIView?) -> CGPoint
let tempPoint = CGPoint(x: 20, y: 20)
let result = toView.convert(tempPoint, from: fromView)

==

let x = (fromView.frame.origin.x + tempPoint.x - toView.frame.origin.x)
let y = (fromView.frame.origin.y + tempPoint.y - toView.frame.origin.y)
let result = CGPoint(x: x, y: y)
3
func convert(_ rect: CGRect, to coordinateSpace: UICoordinateSpace) -> CGRect
open func convert(_ rect: CGRect, to view: UIView?) -> CGRect
let tempRect = CGRect(x: 20, y: 20, width: 50, height: 50)
let result = toView.convert(tempRect, to: fromView)

==

let x = (toView.frame.origin.x + tempRect.origin.x - fromView.frame.origin.x)
let y = (toView.frame.origin.y + tempRect.origin.y - fromView.frame.origin.y)
let width = tempRect.width
let height = tempRect.height
let result = CGRect(x: x, y: y, width: width, height: height)
4
func convert(_ rect: CGRect, from coordinateSpace: UICoordinateSpace) -> CGRect
open func convert(_ rect: CGRect, from view: UIView?) -> CGRect
let tempRect = CGRect(x: 20, y: 20, width: 50, height: 50)
let result = toView.convert(tempRect, from: fromView)

==

let x = (fromView.frame.origin.x + tempRect.origin.x - toView.frame.origin.x)
let y = (fromView.frame.origin.y + tempRect.origin.y - toView.frame.origin.y)
let width = tempRect.width
let height = tempRect.height
let result = CGRect(x: x, y: y, width: width, height: height)
上一篇下一篇

猜你喜欢

热点阅读