【发布时间】:2018-11-06 01:26:27
【问题描述】:
当用户触摸屏幕时,我试图在 Swift 4 中复制图像
var positionArray = Array(repeating: Array(repeating: 0, count: 2), count: 50)
var counter = 0
var pointNum = 0
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
if let touch = touches.first {
let position = touch.location(in: self.view)
let locx = Int(position.x)
let locy = Int(position.y)
positionArray[counter] = [locx, locy]
print(positionArray[counter])
counter = counter + 1
point.center = position
pointNum = pointNum + 1
}
}
如您所见,这是我用来注册触摸的,但我只有一个图像(点)移动到用户触摸的位置。
【问题讨论】:
-
我不确定我是否理解预期的结果。当用户触摸屏幕上的任何位置时,您想复制整个图像吗?因为现在,您正在保存触摸开始时的点数组。没有复制图像的代码。
-
这正是我想要做的:我在某个位置只有一张图像,我希望相同的图像出现在用户触摸的地方而不消除第一个
标签: swift xcode uiimageview touchesbegan