将动画从NSTableView拖放到另一个窗口的NSTextView会退回到源视图而不是文本视图。拖放操作可以正常工作 - 否则我的数据会被粘贴。我的NSTextView的子类具有阳光下的所有拖放协议方法(参见下面的代码)。可能出现什么问题?
- (void)awakeFromNib { // Adjust default insets
[self setTextViewInset];
[self registerForDraggedTypes:[NSArray arrayWithObjects:AWNDragNDropGeneralRuleRecordType, nil]];
[self registerAsObserver];
}
- (void)registerAsObserver
{
[self addObserver:scrollerSubclass
forKeyPath:@"focused"
options:NSKeyValueObservingOptionNew
context:NULL];
}
- (BOOL)acceptsFirstResponder
{
NSLog(@"Accepting");
[self setFocused:YES];
return YES;
}
- (BOOL)resignFirstResponder
{
NSLog(@"Resigning");
[self setFocused:NO];
[super resignFirstResponder]; // Otherwise cursor remains in textView
return YES;
}
- (BOOL)becomeFirstResponder
{
NSLog(@"Becoming");
return YES;
}
- (void)setFocused:(BOOL)x
{
NSLog(@"-setFocused: is called with %d",x);
focused = x;
}
- (BOOL)focused
{
NSLog(@"-focused: is returning %d",focused);
return focused;
}
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
{
NSLog(@"prepareForDragOperation YES");
return YES;
}
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
{
NSLog(@"draggingEntered:");
if ([sender draggingSource] == self) {
return NSDragOperationNone;
}
return NSDragOperationCopy;
}
- (void)draggingExited:(id <NSDraggingInfo>)sender
{
NSLog(@"Draging Exited:");
[self setNeedsDisplay:YES];
}
- (void)draggingEnded:(id < NSDraggingInfo >)sender
{
[self performDragOperation:sender];
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{ // Look for drag source in 'SpellRuleFiles.SpellRulesWindowDelegate tableView delegate method
NSPasteboard *pb = [sender draggingPasteboard];
if (![self readFromPasteboard:pb]) {
NSLog(@"Error: Could not read from dragging pasteboard");
NSLog(@"performDragOperation NO");
return NO;
}
NSLog(@"performDragOperation YES");
return YES;
}
- (BOOL)readFromPasteboard:(NSPasteboard *)pb
{ // Source of paste data is 'SpellRuleFile's '
// I'm not showing this code
return YES;
}
- (void)concludeDragOperation:(id <NSDraggingInfo>)sender
{
NSLog(@"conclude drag operation:");
[self setNeedsDisplay:YES];
}
答案 0 :(得分:0)
在-prepareForDragOperation中:你想设置sender.animatesToDestination = NO,在这种情况下,被拖动的东西会在你放下它们时消失,而不是反弹。
或者,如果你想要更好但更复杂的东西,你可以使用-enumerateDraggingItemsWithOptions:etc:etc:来遍历每个被放到你的文本视图中的项目并适当地设置它们的draggingFrame,在这种情况下是事物被拖动的动画将动画到您选择的最终目的地。