点按并从一个UITable拖到另一个UITable下方

时间:2015-12-14 16:51:42

标签: ios swift uitableview

我有两个UITable,一个在另一个之上。用户可以点击并从顶部表格拖动元素到底部。当元素被拖到底部表格上时,它会消失。

当桌子并排时,没有发生这个问题。

线索/症状可能是;当您滚动顶部表格时,如果您继续将手指向下移动经过顶部桌子和顶部表格,则顶部表格将继续滚动。它就像表格一样延伸到屏幕底部,即使它没有。

问题似乎也只发生在4“屏幕上。

这是拖放功能:

    func dragAndDrop( pangesture : UIPanGestureRecognizer)
{
    print("dragAndDrop \(pangesture.state.rawValue) section=\(section)  row=\(row)")
    if(pangesture.state == UIGestureRecognizerState.Ended)
    {
        if(section == nil)
        {
            return
        }

        let locationInView : CGPoint! = pangesture.locationInView(self.tbldrag)
        if (CGRectContainsPoint(self.tbldrag.bounds, locationInView))
        {
            var moods : [Mood] = getMoodsWithRO(mClient.getRooms()[self.section].getRoomID())

            //dropped to To table
            self.arrDroproom.append(mClient.getRooms()[self.section].getName())

            var temp:Mood = moods[self.row]

            if(moods[self.row].getMoodName() == "Space Off")
            {
                self.arrDropdata.append(mClient.getRooms()[self.section].getRoomID())
            }
            else
            {
                self.arrDropdata.append(moods[self.row].getMoodID())
            }

            self.arrDropmood.append(moods[self.row].getMoodName())
            self.cellDrag.removeFromSuperview()
            self.tblMoods.reloadData()
            self.tbldrag.reloadData()

            addDelayButton.enabled = true

            return
        }
        self.section = nil
        self.row = nil
        if((self.cellDrag) != nil)
        {
            self.cellDrag.removeFromSuperview()
        }
        self.tblMoods.reloadData()
        self.tbldrag.reloadData()
        self.isHorizontalGeasture = false
    }
    else if(pangesture.state == UIGestureRecognizerState.Began)
    {
        let vel : CGPoint = pangesture.velocityInView(self.tblMoods)
        //println(vel)

        let isVerticalGesture : Bool = fabs(vel.y) > fabs(vel.x)

        var a = "horiz"
        if(isVerticalGesture)
        {
            a="vert"
        }
        print("began: gesture is \(a)")


        if((UIDevice.currentDevice().userInterfaceIdiom != .Phone && isVerticalGesture==false) || (UIDevice.currentDevice().userInterfaceIdiom == .Phone))
        {
            self.isHorizontalGeasture = !isVerticalGesture
            if (vel.x > 0)
            {
                //NSLog("towards the right")
            }
            else
            {
                //NSLog("towards the left")
            }
            let touchLocation1 : CGPoint! = pangesture.locationInView(self.tblMoods)

            let indexPath : NSIndexPath? = self.tblMoods.indexPathForRowAtPoint(touchLocation1)

            if(indexPath != nil)
            {
                self.section = indexPath!.section
                self.row = indexPath!.row
                self.cellDrag = self.tblMoods.cellForRowAtIndexPath(indexPath!)!

                self.view.addSubview(self.cellDrag)
            }
        }
    }
    else
    {
        if((UIDevice.currentDevice().userInterfaceIdiom != .Phone && self.isHorizontalGeasture) || (UIDevice.currentDevice().userInterfaceIdiom == .Phone))
        {
            let touchLocation : CGPoint! = pangesture.locationInView(self.view)

            self.cellDrag.center = touchLocation
        }
        else
        {
            pangesture.delegate = nil
        }

    }
}

1 个答案:

答案 0 :(得分:0)

我找到了答案: 当问题发生时,它会发送一个已取消的事件。

“你应该几乎总是使用UIGestureRecognizerState.Ended || UIGestureRecognizerState.Cancelled,因为在手势结束时肯定会调用其中一个。这样你也可以处理用户拖过屏幕的情况。”