Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.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
iOS(iPad)拖放;插入UISplitViewController_Ios_Ipad_Uisplitviewcontroller - Fatal编程技术网

iOS(iPad)拖放;插入UISplitViewController

iOS(iPad)拖放;插入UISplitViewController,ios,ipad,uisplitviewcontroller,Ios,Ipad,Uisplitviewcontroller,我正在一个UISplitViewController(基于Xcode模板项目)中进行从MasterViewController到DetailViewController的D&D工作 - (IBAction)handleGesture:(UIGestureRecognizer *)gesture { CGPoint location; UIWindow *window = [UIApplication sharedApplication].delegate.

我正在一个UISplitViewController(基于Xcode模板项目)中进行从MasterViewController到DetailViewController的D&D工作

- (IBAction)handleGesture:(UIGestureRecognizer *)gesture
    {
        CGPoint location;
        UIWindow *window = [UIApplication sharedApplication].delegate.window;

        //The window doesn't seem to rotate, so we'll get the subview, which does!
        UIView *dragFeedback = [window.subviews objectAtIndex:0];
        if (gesture.state == UIGestureRecognizerStateBegan) {
            location = [gesture locationInView:dragFeedback];

            //which cell are we performing the long hold over?
            NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:[gesture locationInView:self.tableView]];
            UITableViewCell *selecteCell = [self.tableView cellForRowAtIndexPath:indexPath];
            NSLog(@"Cell %@", selecteCell);

            // Create draggable view
            _draggedView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"someImage.png"]];

            // Create drag-feedback window, add the drag-view and make the drag-window visible
            [_draggedView setCenter:location];
            [dragFeedback addSubview:_draggedView];
        }
        else if (gesture.state == UIGestureRecognizerStateChanged) {
            // Update drag-view location
            location = [gesture locationInView:dragFeedback];
            [_draggedView setCenter:location];
        }
        else if (gesture.state == UIGestureRecognizerStateEnded)
        {
            // Disconnect drag-view and hide drag-feedback window
            [_draggedView removeFromSuperview];    

            // Get final location in detailViewController coordinates
            location = [gesture locationInView:self.detailViewController.view];
            [_draggedView setCenter:location];
            [self.detailViewController.view addSubview:_draggedView];
        }
        else {
            NSLog(@"%s unrecognized gesture %d", __FUNCTION__, gesture.state);
        }
    }
基本上,我要做的是创建一个UILongPressGestureRecognitor,并将其放置在MasterViewController的self.tableview属性上

- (IBAction)handleGesture:(UIGestureRecognizer *)gesture
    {
        CGPoint location;
        UIWindow *window = [UIApplication sharedApplication].delegate.window;

        //The window doesn't seem to rotate, so we'll get the subview, which does!
        UIView *dragFeedback = [window.subviews objectAtIndex:0];
        if (gesture.state == UIGestureRecognizerStateBegan) {
            location = [gesture locationInView:dragFeedback];

            //which cell are we performing the long hold over?
            NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:[gesture locationInView:self.tableView]];
            UITableViewCell *selecteCell = [self.tableView cellForRowAtIndexPath:indexPath];
            NSLog(@"Cell %@", selecteCell);

            // Create draggable view
            _draggedView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"someImage.png"]];

            // Create drag-feedback window, add the drag-view and make the drag-window visible
            [_draggedView setCenter:location];
            [dragFeedback addSubview:_draggedView];
        }
        else if (gesture.state == UIGestureRecognizerStateChanged) {
            // Update drag-view location
            location = [gesture locationInView:dragFeedback];
            [_draggedView setCenter:location];
        }
        else if (gesture.state == UIGestureRecognizerStateEnded)
        {
            // Disconnect drag-view and hide drag-feedback window
            [_draggedView removeFromSuperview];    

            // Get final location in detailViewController coordinates
            location = [gesture locationInView:self.detailViewController.view];
            [_draggedView setCenter:location];
            [self.detailViewController.view addSubview:_draggedView];
        }
        else {
            NSLog(@"%s unrecognized gesture %d", __FUNCTION__, gesture.state);
        }
    }
下面是我的手势识别器

- (void)gestureHandler:(UIGestureRecognizer*)gesture
{
    CGPoint location;
    NSIndexPath* indexPath = [self.tableView indexPathForRowAtPoint:[gesture locationInView:self.tableView]];
    if (gesture.state == UIGestureRecognizerStateBegan) {
        // Create draggable view
        NSString* imageCanvasName = [self imageNameByIndexPath:indexPath isDetail:YES];
        UIImage* imageCanvas = [UIImage imageNamed:imageCanvasName];
        _draggedView = [[UIImageView alloc] initWithImage:imageCanvas];

        // Create drag-feedback window, add the drag-view and make the drag-window visible
        CGRect windowFrame = self.view.window.frame;
        _dragFeedbackWindow = [[UIWindow alloc] initWithFrame:windowFrame];
        location = [gesture locationInView:gesture.view.window];
        [_draggedView setCenter:location];
        [_dragFeedbackWindow addSubview:_draggedView];
        [_dragFeedbackWindow setHidden:NO];     
    }
    else if (gesture.state == UIGestureRecognizerStateChanged) {
        // Update drag-view location
        location = [gesture locationInView:gesture.view.window];
        [_draggedView setCenter:location];
    }
    else if (gesture.state == UIGestureRecognizerStateEnded)
    {
        // Disconnect drag-view and hide drag-feedback window
        [_draggedView removeFromSuperview];     
        [_dragFeedbackWindow setHidden:YES];

        // If drop is in a valid location...
        if ([self.tableView pointInside:_draggedView.center withEvent:nil] == NO)
        {
            // Get final location in detailViewController coordinates
            location = [gesture locationInView:self.detailViewController.view];
            [_draggedView setCenter:location];
            [self.detailViewController.view addSubview:_draggedView];
        }
    }
    else {
        NSLog(@"%s unrecognized gesture %d", __FUNCTION__, gesture.state);
    }
}
当iPad处于纵向模式时,所有这些都能很好地工作——拖拽,拖拽,拖拽

如果iPad旋转,我的问题就开始了。。。 在这种情况下,my_draggedView显示为“反向旋转”——它将“反映”iPad的旋转——直到掉落

这就像我必须对dragFeedbackWindow应用一些旋转-但我尝试了很多方法,失败了

有什么想法吗

谢谢

好的-我找出了发生这种情况的“原因”和“如何”修复(并将附加处理程序代码以正确执行此操作),所有这些都在下面

下面是代码…“只是”将其添加到MAsterViewController中(如果-像我一样-您想从主视图拖动到详细视图…)

现在,长按手势处理程序

- (void)gestureHandler:(UIGestureRecognizer*)gesture
{
    CGPoint location;
    UIWindow* dragFeedback = [UIApplication sharedApplication].delegate.window;
    if (gesture.state == UIGestureRecognizerStateBegan) {
        // Create draggable view
        _draggedView = [[UIImageView alloc] initWithImage:@"someImage.png"];

        // Required to adapt orientation... WORKS, BUT WHY NEEDED???
        [_draggedView rotateToOrientation:[[UIApplication sharedApplication] statusBarOrientation]];

        // Create drag-feedback window, add the drag-view and make the drag-window visible
        location = [gesture locationInView:dragFeedback];
        [_draggedView setCenter:location];
        [dragFeedback addSubview:_draggedView];
    }
    else if (gesture.state == UIGestureRecognizerStateChanged) {
        // Update drag-view location
        location = [gesture locationInView:dragFeedback];
        [_draggedView setCenter:location];
    }
    else if (gesture.state == UIGestureRecognizerStateEnded)
    {
        // Disconnect drag-view and hide drag-feedback window
        [_draggedView removeFromSuperview];     

        // Get final location in detailViewController coordinates
        location = [gesture locationInView:self.detailViewController.view];
        [_draggedView setCenter:location];
        // "Noramlize" orientation... WORKS, BUT WHY NEEDED???
        [_draggedView rotateToOrientation:UIInterfaceOrientationPortrait];
        [self.detailViewController.view addSubview:_draggedView];
    }
    else {
        NSLog(@"%s unrecognized gesture %d", __FUNCTION__, gesture.state);
    }
}

这就像一个符咒-让我知道它是如何为你工作的(如果你需要一个样本项目,让我知道…

谢谢你的解决方案!你给了我90%的方法。作为付款,我会给你最后10%:)

问题似乎是UIWindow永远不会旋转,只有它的子视图会旋转!因此,解决方案是使用子视图

我还添加了一些代码,显示如何查看选择的单元格(假设主视图是UITableViewController)


嗨,鲁文,我也有同样的要求。你能分享一个样本项目吗。谢谢,当然可以。我要花一天的时间来清理。非常感谢。让我看看。嗨,鲁文,它在工作。在触摸图像后,我不得不用手指在图像上多停留一点时间!非常感谢你。这是一个惊人的例子@AppleDeveloper,基本上,此示例显示从拖动区域拖动对象(多个对象之一)。到目前为止,你还可以,这是你所需要的。下一部分是决定(在“拖放”被拖动对象的过程中)拖放区域(我的示例中的self.detailViewController)是否“愿意”接受“被拖动”对象。一个足够简单的解决方案是向self.detailViewController添加一个方法“canAcceptObject:draggedObject”,测试它是否“愿意”接受拖动(意思是“它是否是特定问题的正确答案”)。有意义吗?RefuX,当您的更改“清除”手动旋转的需要时,它不再提供拖动菜单“顶部”的视觉反馈。。。参见我发布的示例:Ahhh。。我从来没有在肖像模式下测试过:)是的,我认为要超越弹出窗口,你必须在UIWindow上绘制。我做了更多的研究,并确认了这一点:“窗口本身并没有改变坐标系,它对其子视图应用了一个变换,从而改变了它们的坐标系。”所以至少现在一切都有意义了吗?:)当然有。谢谢你的确认。