objective-c - UIScrollView 的 subview 中的拖动事件

标签 objective-c ios drag-and-drop

如何向 UIScrollView 的 subview 添加拖动事件?结构如下:

-UIView
   -UIScrollView
      -UIView
      -UIView
        ...

我试着从以下开始:

-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *aTouch = [touches anyObject];
CGPoint location = [aTouch locationInView:self.superview.superview];
[UIView beginAnimations:@"Dragging A DraggableView" context:nil];
self.frame = CGRectMake(location.x, location.y, 
                        self.frame.size.width, self.frame.size.height);
[UIView commitAnimations];

但是没有任何反应!帮助将不胜感激。 谢谢

最佳答案

为了防止有人像我一样发现这个问题,我通过向 ScrollView 中的 subview 添加手势识别器解决了这个问题。手势识别器将自行处理触摸事件。

关于objective-c - UIScrollView 的 subview 中的拖动事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7365520/

相关文章:

javascript - 无法使用拖动控件

java 。将图像图标从 jpanel 1 上的 JLabel 拖放到 panel 2 上的 JLabel。添加计数器功能

javascript - 在 contenteditable 中模拟拖动类型文本/普通行为

ios - Sprite Kit中的节点数据

ios - 将数据转换为字符串得到 nil 值

ios - Objective-C CGAffineTransformRotate 不起作用

ios - "Application validation was skipped"因为无法加载 "the bundle “ITunesSoftwareService””

iphone - 试图在 UIPanGestureRecognizer 上移动 UIImageView

iphone - 迭代嵌套 JSON 数组 iPhone

ios - 在 web 服务代码中解包 Optional 值时意外发现 nil