将触摸传输到 UIImageView 的副本
我经历了漫长的旅程,试图将 UIImageViews 从 UITableView 拖放到另一个视图。
我让一切都按部就班。我对 UIPanGestureRecognizer 进行子类化,并将此自定义识别器附加到我加载到表视图中的所有 UIImageView。
然后,我重写识别器的 TouchMoved 方法,除其他外,将临时视图添加到应用程序键窗口上,然后将所选 UIImageView 的副本添加到该临时视图上,如下所示:
UIView *dragAndDropView = [[UIView alloc] initWithFrame: [[UIScreen mainScreen] applicationFrame]];
dragAndDropView.backgroundColor = [UIColor whiteColor];
[[UIApplication sharedApplication].keyWindow addSubview: dragAndDropView];
ElementImageView * sourceImageView = (ElementImageView*)self.view;
ElementImageView *newImageView = [[ElementImageView alloc] initWithImage:sourceImageView.image];
newImageView.userInteractionEnabled = YES;
newImageView.frame = [self.view convertRect:sourceImageView.frame toView:dragAndDropView];
[dragAndDropView addSubview:newImageView];
作为此代码的结果,我确实得到了我的dragAndDropView 顶部的源图像视图的副本(我可以看出,因为我将dragAndDropView 的背景颜色设置为白色)。如果我抬起手指并再次触摸复制的图像视图,我当然可以根据需要将其在屏幕上拖动。但我找不到一种方法将现有的触摸无缝转移到新对象。
有什么想法吗?
I've been a long journey trying to drag and drop UIImageViews from a UITableView to another view.
I have everything working to a point. I subclass UIPanGestureRecognizer and attach this custom recognizer to all the UIImageViews I load into the table view.
I then override the recognizer's touchesMoved method to, among other things, add a temporary view onto the applications key window, then add a copy of the selected UIImageView onto this temporary view, as follows:
UIView *dragAndDropView = [[UIView alloc] initWithFrame: [[UIScreen mainScreen] applicationFrame]];
dragAndDropView.backgroundColor = [UIColor whiteColor];
[[UIApplication sharedApplication].keyWindow addSubview: dragAndDropView];
ElementImageView * sourceImageView = (ElementImageView*)self.view;
ElementImageView *newImageView = [[ElementImageView alloc] initWithImage:sourceImageView.image];
newImageView.userInteractionEnabled = YES;
newImageView.frame = [self.view convertRect:sourceImageView.frame toView:dragAndDropView];
[dragAndDropView addSubview:newImageView];
As a result of this code, I do indeed get a copy of the source image view on top of my dragAndDropView (I can tell because I set the backgroundcolor of the dragAndDropView to white). And if I lift my finger and touch the copied image view again, I can of course drag it around the screen as I wish. But I can't find a way to seamlessly transfer the existing touch to the new object.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您可以在 UIPanGestureRecognizer 处理程序上执行以下操作:
希望有帮助。
I think you could do the following on your UIPanGestureRecognizer handler:
Hope it helps.