如何启用 IKImageBrowserView 的特定项目上的拖动?
我正在将 IKImageBrowserView 用于我当前正在开发的 mac 应用程序,并希望在 IKImageBrowserView 内部启用拖动功能,因此我使用了 – setAllowsDroppingOnItems: 但不幸的是这不允许我指定哪些项目有资格作为放置目的地,因此问题的第一部分是是否有一种简单直接的方法来做到这一点。
我搜索了文档并想出了一种方法,其中包括使用拖动委托方法 - (NSDragOperation)draggingUpdated:(id < NSDraggingInfo >)sender
NSUInteger index = [browserView indexOfItemAtPoint:sender.draggingLocation];
if(index != NSNotFound)
{
WCItemObject *browserCell = (WCItemObject *)[self.items objectAtIndex:index];
NSLog(@"%@", browserCell.path);
}
从逻辑上讲,这应该有效,但事实并非如此。如果项目很少(不显示垂直滚动条),它只会给出正确的对象,这使我相信 indexOfItemAtPoint 不考虑滚动视图,因此如果是这样,我可能需要覆盖它(这是第二部分)问题)我该怎么做。
I'm using an IKImageBrowserView for a mac application I'm currently developing and wants to enable dragging inside the IKImageBrowserView so I've used – setAllowsDroppingOnItems: but unfortunately this doesn't allow me to specify which items are eligible as a drop destination so the first part of the question would be if there is a simple and straightforward way to do that.
I've searched the documentation and came up with a way that consists in using the drag delegate method - (NSDragOperation)draggingUpdated:(id < NSDraggingInfo >)sender
NSUInteger index = [browserView indexOfItemAtPoint:sender.draggingLocation];
if(index != NSNotFound)
{
WCItemObject *browserCell = (WCItemObject *)[self.items objectAtIndex:index];
NSLog(@"%@", browserCell.path);
}
Logically, this should be working but, it's not. It only gives the correct object if there are few items (to not display the vertical scroller) which leads me to believe that indexOfItemAtPoint doesn't account for the scroll view so I might need to override it if so (this is the second part of the question) how shall I do it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过使用indexAtLocationOfDroppedItem(IKImageBrowserView 的一种方法)来使其工作,从名称和文档来看,它听起来好像只在放置发生后更新,但实际上它在悬停时更新。
I got it working by using indexAtLocationOfDroppedItem (a method of IKImageBrowserView) which from the name and the documentation sounds like if only updates after the drop occurs but it actually updates on hover.