objective-c - 在 View Controller 之间拖放(包含在同一个 View Controller 中)
<p><p>我有一个 ViewController ,它显示在 Split View的详细 View 中,由 <strong>TableView</strong> 和 <strong>Core Plot chart</strong>View 组成,如下所示: </p>
<p> <img src="/image/hJXJO.png" alt="My view controller"/> </p>
<p>我希望能够将单个 TableViewCell 拖放到 Core PlotView 中。 </p>
<p>由于手势识别器只能绑定(bind)到一个 View ,因此最好的方法是什么? </p>
<p>如何为拖放 Action 设置动画?</p>
<h2>关于 ViewController 包含的其他问题</h2>
<p>如果两者都包含在同一个 ViewController 容器中(如在 iOS 5 中),我如何实现从一个 ViewController 拖放到另一个 ViewController 。</p>
<p>谢谢!</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>下面是一些代码,用于将 Split View左侧面板上的表格 View 中的一行拖动到右侧面板详细信息屏幕。这似乎与您的问题相似,尽管不可否认。无论如何,我个人是通过长按触发拖放:</p>
<pre><code>UILongPressGestureRecognizer *longPress = [ initWithTarget:self action:@selector(longPress:)];
;
</code></pre>
<p>然后我的处理程序执行以下操作:</p>
<pre><code>- (IBAction)longPress:(UIGestureRecognizer *)sender
{
if (sender.state == UIGestureRecognizerStateBegan)
{
// figure out which item in the table was selected
NSIndexPath *indexPath = ];
if (!indexPath)
{
_inDrag = NO;
return;
}
_inDrag = YES;
// get the text of the item to be dragged
NSString *text = description]];
// create item to be dragged, in this example, just a simple UILabel
UIView *splitView = self.splitViewController.view;
CGPoint point = ;
UIFont *font = ;
CGSize size = ;
CGRect frame = CGRectMake(point.x - (size.width / 2.0), point.y - (size.height / 2.0), size.width, size.height);
_draggedView = [ initWithFrame:frame];
;
;
];
// now add the item to the view
;
}
else if (sender.state == UIGestureRecognizerStateChanged && _inDrag)
{
// we dragged it, so let's update the coordinates of the dragged view
UIView *splitView = self.splitViewController.view;
CGPoint point = ;
_draggedView.center = point;
}
else if (sender.state == UIGestureRecognizerStateEnded && _inDrag)
{
// we dropped, so remove it from the view
;
// and let's figure out where we dropped it
UIView *detailView = self.detailViewController.view;
CGPoint point = ;
UIAlertView *alert;
if (CGRectContainsPoint(detailView.bounds, point))
alert = [ initWithTitle:@"dropped in details view" message:nil delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
else
alert = [ initWithTitle:@"dropped outside details view" message:nil delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
;
}
}
</code></pre></p>
<p style="font-size: 20px;">关于objective-c - 在 ViewController 之间拖放(包含在同一个 ViewController 中),我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/11245043/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/11245043/
</a>
</p>
页:
[1]