0
將動畫從NSTableView拖放到另一個窗口的NSTextView反衝回源視圖而不是textview。拖放操作很好,否則我的數據被粘貼。我的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];
}
感謝您的建議,但動畫仍然反彈。我的直覺是,通過使用NSTextView的子類,它的窗口First Responder不會對拖動事件做出反應。我不知道該如何處理這種可能性。 – Antony
我遇到同樣的問題。你找到解決方案嗎? –