我畫了一個矩形。當我觸摸屏幕時,我可以改變寬度和高度。 默認情況下,我使x = 50,y = self.view.frame.height/2。我需要相對於x和y拉伸矩形。如何更改x和y?如何更改CGRect的x和y?
var scanRectangleRect = CGRect.zero
var scanRectangle: UIView = UIView()
func drawLine() {
self.view.addSubview(scanRectangle)
scanRectangle.backgroundColor = UIColor.gray
scanRectangleRect = CGRect(x: 50, y: self.view.frame.height/2, width: 400, height: 150)
scanRectangle.frame = scanRectangleRect
scanRectangle.center = CGPoint(x: scanRectangle.center.x, y: self.view.frame.height/2)
scanRectangle.isHidden = false
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
scanRectangle.frame.size.height += 10
scanRectangle.frame.size.width += 10
}
矩形正在移動,但我需要伸展它。 – kvv
@Kazak你讀過https://developer.apple.com/documentation/coregraphics/cgrect作爲sulthan鏈接? – 2017-09-04 18:30:31
@Sneak是的,我做到了。 – kvv