首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >作为拖动目标的Webview?

作为拖动目标的Webview?
EN

Stack Overflow用户
提问于 2013-08-21 11:10:08
回答 1查看 151关注 0票数 0

好的,下面是我需要的(虽然我还没有找到真正的答案):

  • 我有一个简单朴素的WebView
  • 我需要能够把物品放到那个WebView上。

我尝试过通过WebUIDelegate及其方法,甚至registerForDraggedTypes,但仍然没有成功。

有什么想法吗?有什么地方有关于如何实现这一目标的完整例子?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-09 13:50:05

我在我的申请中这么做了,以下是重点,如果你还在找,

让它接受掉到webview中。

代码语言:javascript
运行
复制
[self registerForDraggedTypes:
 [NSArray arrayWithObjects:MyPrivateTableViewDataType,NSFilenamesPboardType,nil]];

输入句柄拖动以验证/验证正在拖动的项。

代码语言:javascript
运行
复制
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender{
    pboard = [sender draggingPasteboard];

    if ( [[pboard types] containsObject:MyPrivateTableViewDataType] ) {
        if (sourceDragMask & NSDragOperationGeneric) {
            return NSDragOperationGeneric;
        }
    }

}
- (BOOL)prepareForDragOperation:(id < NSDraggingInfo >)sender{
    NSPasteboard *pboard;

    pboard = [sender draggingPasteboard];

    if ( [[pboard types] containsObject:MyPrivateTableViewDataType] ) {
        // Only a copy operation allowed so just copy the data
        return YES;
    }
    else if ( [[pboard types] containsObject:NSURLPboardType] ) {
        return YES;

    }
    return NO;
}

并最终执行/完成拖放。

代码语言:javascript
运行
复制
- (BOOL)performDragOperation:(id < NSDraggingInfo >)sender{

    NSPasteboard *pboard;

    pboard = [sender draggingPasteboard];

    if ( [[pboard types] containsObject:MyPrivateTableViewDataType] ) {
        // Only a copy operation allowed so just copy the data
            return YES;
        }
        else{
            return NO;
        }

    } else if ( [[pboard types] containsObject:NSURLPboardType] ) {
        NSURL *url = [NSURL URLFromPasteboard: pboard];
        NSString *filePath= [url path];
        return YES;
    }

    return NO;
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18355841

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档