Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 将UIImageview拖出UIScrollview_Iphone_Uiscrollview_Uiimageview_Drag - Fatal编程技术网

Iphone 将UIImageview拖出UIScrollview

Iphone 将UIImageview拖出UIScrollview,iphone,uiscrollview,uiimageview,drag,Iphone,Uiscrollview,Uiimageview,Drag,我在uiscrollview中有许多UIImageView。我正在尝试将uiimageview从uiscrollview中拖出。我对uiscollview进行了子类化,并编写了custon touchBegind、toucmoved和touchEnd方法,以便在scroll拖动事件上将touch传递给scrollview超类,并在scroll-events以外的事件上传递给我的主viewcontroller类touchmethods。 要将uiimageview从uiscrollview中拖出,

我在uiscrollview中有许多UIImageView。我正在尝试将uiimageview从uiscrollview中拖出。我对uiscollview进行了子类化,并编写了custon touchBegind、toucmoved和touchEnd方法,以便在scroll拖动事件上将touch传递给scrollview超类,并在scroll-events以外的事件上传递给我的主viewcontroller类touchmethods。 要将uiimageview从uiscrollview中拖出,我将其从superview(scrollview)中移除,并将其添加到TouchView方法的mainview中。 my uiimageview已从scrollview中删除,并成功添加到mainview。 现在这里的问题是:在第一次触摸时,我的touchBegind方法被调用,但是当我移动uiimageview时,touchmoved方法没有被调用。 在第二次触摸之后,uiimageview中的所有内容都会从scrollview中拖出


更新:我对UIImageView类进行了子类化,并在UIImageView子类中编写了touchBegind、touchmoved和touchEnd方法,现在它正在工作。以前我使用的是mainview的touch方法,所以touch方法也考虑在UICollView上进行触摸。但现在只考虑在UIImageView上进行触摸。我还添加了另一个更改:我在TouchStart禁用了滚动,并在touchend启用了滚动。Thanx最适合我的方法是不要移动scrollview中的uiImageView,而是创建一个复制视图(在控制视图控制器中)并通过触摸移动该视图,然后将其添加到主视图,然后删除原始视图

如果用户中途改变主意,最终决定不把它拖出去,这种方法看起来也会更好

编辑: 我检查了我的应用程序来刷新我自己所做的事情,但我也没有在原始项目上移动或结束。我在slideview中的每个视图上都有一个手势识别器,当启动该识别器时,它会告诉代理(作为scrollview父视图的viewcontroller)拖动正在进行。通过传递的对象,我可以获得CGPoint并相应地采取行动:

UILongPressGestureRecognizer *myRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(drag:)];
[myRecognizer setDelegate:self];
[myItemInsideScrollView addGestureRecognizer:myRecognizer];


-(void)drag:(UILongPressGestureRecognizer *)sender {
    [self.view bringSubviewToFront:[(UILongPressGestureRecognizer*)sender view]];
    CGPoint translatedPoint = [sender locationInView:self.view];

    // if we are not already dragging we create the duplicate view
    // if we are already dragging just update the location of the duplicate view

    // next check if drag has ended and if so call a method to do what we want
    if ( dragging ) {
        if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) {
            [self checkForDragRelease:(CGPoint)translatedPoint];
        }
    }

}

对我来说,最有效的方法是不移动scrollview中的uiImageView,而是创建一个重复的视图(在控制视图控制器中),并通过触摸移动该视图,然后将其添加到主视图,然后删除原始视图

如果用户中途改变主意,最终决定不把它拖出去,这种方法看起来也会更好

编辑: 我检查了我的应用程序来刷新我自己所做的事情,但我也没有在原始项目上移动或结束。我在slideview中的每个视图上都有一个手势识别器,当启动该识别器时,它会告诉代理(作为scrollview父视图的viewcontroller)拖动正在进行。通过传递的对象,我可以获得CGPoint并相应地采取行动:

UILongPressGestureRecognizer *myRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(drag:)];
[myRecognizer setDelegate:self];
[myItemInsideScrollView addGestureRecognizer:myRecognizer];


-(void)drag:(UILongPressGestureRecognizer *)sender {
    [self.view bringSubviewToFront:[(UILongPressGestureRecognizer*)sender view]];
    CGPoint translatedPoint = [sender locationInView:self.view];

    // if we are not already dragging we create the duplicate view
    // if we are already dragging just update the location of the duplicate view

    // next check if drag has ended and if so call a method to do what we want
    if ( dragging ) {
        if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) {
            [self checkForDragRelease:(CGPoint)translatedPoint];
        }
    }

}

我尝试在主视图的相同位置创建新视图并释放旧视图,但问题仍然存在。在新视图上未调用touch events方法我尝试在主视图的相同位置创建新视图并释放旧视图,但问题仍然存在。在newview上不会调用touch events方法