【问题标题】:Objective C: Drag and Drop on UIScrollView目标 C:在 UIScrollView 上拖放
【发布时间】:2012-02-17 09:07:35
【问题描述】:

我正在尝试在 UIScrollView 上创建拖放功能,但在我的舞台上这对我来说非常混乱,因为我是初学者。我尝试使用触摸事件,但失败了(尽管它适用于没有 UIScrollView 的项目)我阅读了一些有关此问题的信息,他们建议使用手势识别器,所以我这样做了。

我的问题弓是这个,我可以拖动它但是它被延迟了,我的意思是,我需要在长按后再次触摸图像才能拖动它......

我的长按手势上有这个代码:

-(void) handleLongPress:(UILongPressGestureRecognizer *)recognizer  { 
    switch (recognizer.state) {
        case UIGestureRecognizerStateBegan:
            [img1 setFrame:CGRectMake(400, 385, 300, 300)];
            [scrollPaging setScrollEnabled:NO];
            [scrollPaging setUserInteractionEnabled:NO];
            break;

这在 touchesMoved 上:

UITouch *touch =[[event allTouches] anyObject];

    location=[touch locationInView:self.view];
    img1.center=location;
        return;

谢谢!

【问题讨论】:

  • 嘿 Crisn,我需要将图像从滚动视图拖动到 self.view,反之亦然。你能有任何样品吗?

标签: objective-c ios uiscrollview uigesturerecognizer


【解决方案1】:

尝试使用 UIPanGestureRecognizer 来拖动而不是 touchesMoved。还为平移和长按识别器设置委托并添加此方法:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES; }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多