[英]Move objects around, with gesture recognizer for multiple Objects
I am trying to make an app where you can use Stickers like on Snapchat and Instagram. 我正在尝试开发一个可以在Snapchat和Instagram上使用Stickers的应用程序。 It fully worked to find a technique, that adds the images, but now I want that if you swipe the object around the object changes its position (I also want to make the scale / rotate function).
找到一种添加图像的技术完全可行,但是现在我希望如果在对象周围滑动对象会更改其位置(我也想创建缩放/旋转功能)。
My code looks like this: 我的代码如下所示:
@objc func StickerLaden() {
for i in 0 ..< alleSticker.count {
let imageView = UIImageView(image: alleSticker[i])
imageView.frame = CGRect(x: StickerXScale[i], y:StickerYScale[i], width: StickerScale[i], height: StickerScale[i])
ImageViewsSticker.append(imageView)
ImageView.addSubview(imageView)
imageView.isUserInteractionEnabled = true
let aSelector : Selector = "SlideFunc"
let slideGesture = UISwipeGestureRecognizer(target: self, action: aSelector)
imageView.addGestureRecognizer(slideGesture)
}
}
func SlideFunc(fromPoint:CGPoint, toPoint: CGPoint) {
}
Here are the high-level steps you need to take: 这是您需要采取的高级步骤:
UIPanGestureRecognizer
to the parent view that has the images on it. UIPanGestureRecognizer
添加到上面有图像的父视图。 UIGestureRecognizerDelegate
methods to keep track of the user touching and releasing the screen. UIGestureRecognizerDelegate
方法以跟踪用户触摸和释放屏幕的情况。 image.frame.contains(touchPoint)
. image.frame.contains(touchPoint)
。 Add all images that are under the touch point to an array. The above will give you a nicely working pan solution. 以上将为您提供一个很好的平底锅解决方案。 It's a good amount of things you need to sort out, but it's not very difficult.
您需要整理很多东西,但这并不是很难。
As I said in my comment, scale and rotate are very tricky. 正如我在评论中所说, 缩放和旋转非常棘手。 I advise you to forget that for a bit and first implement other parts of your app.
我建议您先忘记这一点,然后首先实现应用程序的其他部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.