Issue with Custom View Drag and Drop
Issue with Custom View Drag and Drop
- Subject: Issue with Custom View Drag and Drop
- From: Omkar Ramtekkar <email@hidden>
- Date: Wed, 20 Feb 2013 13:34:30 +0000
- Thread-topic: Issue with Custom View Drag and Drop
Hello,
I'm implementing the Drag and Drop functionality over the same Custom View. My6 Custom is acting as source and Destination. I've implemented it according to Apple's Guideline for Drag and Drop wit Custom Views. I've started the Drag and Drop from mouseDown: event.
Normally it works fine, no issues. But sometimes performDragDropOperation: doesn't get called, instead mouseUp event gets called.
In successful scenario(When drag and drop works fine) I never get call to mouseUp: but when performDragDropOperation: doesn't get called I get the call to mouseUp event.
I also observed that when mouseUp gets called after that call gets stuck in draggingUpdated: - means draggingUpdated gets called repeatedly(I verified it using console print messages) even if I hover over my Custom View. To finish the drag and drop I have to click twice or thrice on view.
Following is the code for the same.
-(void)mouseDown:(NSEvent *)pTheEvent {
lastPoint = [pTheEvent locationInWindow];
NSPoint tvarMouseInWindow = [pTheEvent locationInWindow];
NSPoint tvarMouseInView = [self convertPoint:tvarMouseInWindow
fromView:nil];
NSSize zDragOffset = NSMakeSize(0.0, 0.0);
NSPasteboard *zPasteBoard;
zPasteBoard = [NSPasteboard pasteboardWithName:NSDragPboard];
[zPasteBoard declareTypes:[NSArray arrayWithObject:NSTIFFPboardType]
owner:self];
[zPasteBoard setData:[self.nsImageObj TIFFRepresentation]
forType:NSTIFFPboardType];
dragImage = [NSImage imageNamed:@"dragimage1"];
[self dragImage:dragImage
at:tvarMouseInView
offset:zDragOffset
event:pTheEvent
pasteboard:zPasteBoard
source:self
slideBack:YES];
return;
}
- (NSDragOperation)draggingEntered:(id )sender
{
return NSDragOperationMove;
}
- (BOOL)prepareForDragOperation:(id )sender {
return YES;
}
- (BOOL)performDragOperation:(id )sender {
NSPasteboard *zPasteboard = [sender draggingPasteboard];
self.nsImageObj = [[NSImage alloc] initWithPasteboard: zPasteboard];
return YES;
}
- (void)concludeDragOperation:(id )sender {
[self setNeedsDisplay:YES];
}
- (void)draggedImage:(NSImage *)image movedTo:(NSPoint)screenPoint
{
NSPoint pt = [[self window] convertScreenToBase:screenPoint];
lastPoint = [self convertPoint:pt fromView: nil];
dragImage = image;
[self setNeedsDisplay:YES];
}
-(void)mouseDragged:(NSEvent *)pTheEvent {
lastPoint = [pTheEvent locationInWindow];
[self setNeedsDisplay:YES];
} // end mouseDragged
-(void) mouseUp:(NSEvent *)theEvent
{
lastPoint = [theEvent locationInWindow];
[self setNeedsDisplay:YES];
}
- (BOOL)becomeFirstResponder
{
return YES;
}
Regards
Omkar
DISCLAIMER
==========
This e-mail may contain privileged and confidential information which is the property of Persistent Systems Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Ltd. does not accept any liability for virus infected mails.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden