目标C:在UIScrollView上拖放

时间:2012-01-24 02:40:56

标签: objective-c ios uiscrollview uigesturerecognizer

我正在尝试在UIScrollView上制作拖放功能,这对我来说非常困惑,因为我是初学者。我尝试使用触摸事件,但我失败了(虽然它适用于没有UIScrollView的项目)我读了一些关于这个问题,他们建议使用手势识别器,所以我做了。

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

我的Longpress手势上有这个代码:

-(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;

谢谢!

1 个答案:

答案 0 :(得分:1)

尝试使用UIPanGestureRecognizer拖动而不是touchesMoved。同时为pan和long press识别器设置委托并添加此方法:

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