简体   繁体   English

在iOS中的MAster-DetailView控制器中拖放

[英]Drag & Drop in MAster-DetailView Controller in iOS

I want to drag from the masterview tableview Cell to DetailView. 我想从masterview tableview单元格拖动到DetailView。

I try with touchesBegan & touchesEnded method but not working. 我尝试使用touchesBegan和touchesEnded方法,但无法正常工作。

Can you please help me for this? 你能帮我吗?

Thank you 谢谢

This is actually not easy. 这实际上并不容易。 You can start by 你可以开始

  1. Adding a pan gesture recognizer ( UIPanGestureRecognizer ) to the root view controller's view ( UIWindow.keyWindow!.rootViewController!.view ). 将平移手势识别器( UIPanGestureRecognizer )添加到根视图控制器的视图( UIWindow.keyWindow!.rootViewController!.view )。

  2. When the pan starts (ie user touches the screen), loop through the master view's table view's visible cells to see if the point is inside any cell by using UIView 's convertPoint:fromView: . 平移开始时(即用户触摸屏幕),使用UIViewconvertPoint:fromView:循环浏览主视图的表视图的可见单元格,以查看该点是否在任何单元格内。 You may need to adjust timing to avoid interfering with table view's scrolling and tapping. 您可能需要调整时间以避免干扰表视图的滚动和点击。

  3. If a cell contains the pan's point, create an "indicator view" (that shows that user is dragging) and add it to the root view controller's view, on top of everything else and position it properly, eg under user's finger. 如果单元格包含平移点,则创建一个“指示器视图”(表明用户正在拖动),并将其添加到根视图控制器的视图中,位于所有其他对象之上,并将其正确放置在例如用户的手指下。

  4. When the pan changes (ie user moves his finger), update the indicator view's location. 当平移发生变化(即用户移动手指)时,请更新指标视图的位置。

  5. When the pan ends (ie user releases his finger), check if the point is inside the detail view and do whatever you need to do. 平移结束时(即用户松开手指),检查该点是否在局部视图内,然后执行所需的任何操作。

Check this out. 检查这个出来。 It demonstrates how to do drag drop within a view. 它演示了如何在视图中进行拖放。 Your problem is more complicated as it involves different view controllers, hence the touch handling must be done at a level higher than both master and detail view controllers. 您的问题更加复杂,因为它涉及不同的视图控制器,因此触摸处理必须在比主视图控制器和局部视图控制器更高的级别上进行。

Why are you using touchesBegan & touchesEnded methods? 为什么要使用touchesBegan和touchesEnded方法? If you have the tableView you should use didSelectRowAtIndexPath delegate method. 如果具有tableView,则应使用didSelectRowAtIndexPath委托方法。 And you can also use segues if you are using storyboards. 如果使用情节提要板,也可以使用segues。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM