2014-02-28 86 views
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]; 
} 

回答

0

在-prepareForDragOperation:你想設置sender.animatesToDestination = NO,在這種情況下,越來越拖累事情只會當你放下,而不是反衝回他們,消失。或者,如果你想要更好但更復雜的東西,你可以使用-enumerateDraggingItemsWithOptions:etc:etc:來瀏覽每一個被放到你的文本視圖並適當地設置它們的draggingFrame的項目,在這種情況下,被拖動的東西將動畫成你選擇的最終目的地。

+0

感謝您的建議,但動畫仍然反彈。我的直覺是,通過使用NSTextView的子類,它的窗口First Responder不會對拖動事件做出反應。我不知道該如何處理這種可能性。 – Antony

+0

我遇到同樣的問題。你找到解決方案嗎? –