Re: how to implement iphoto like animation while doing drag and drop on custom listview
Re: how to implement iphoto like animation while doing drag and drop on custom listview
- Subject: Re: how to implement iphoto like animation while doing drag and drop on custom listview
- From: Chuck Soper <email@hidden>
- Date: Wed, 13 Mar 2013 09:19:43 -0700
- Thread-topic: how to implement iphoto like animation while doing drag and drop on custom listview
Take a look at the MultiPhotoFrame sample source:
http://developer.apple.com/library/mac/#samplecode/MultiPhotoFrame/Introduc
tion/Intro.html
The dragged images are animated as they enter/exit views by tracking the
mouse using this NSDraggingSource Protocol method:
- (void)draggingSession:(NSDraggingSession *)session
movedToPoint:(NSPoint)screenPoint
Also, check out the following WWDC 2011 video. It explains how to change
"drag images in flight."
https://developer.apple.com/videos/wwdc/2011/?id=115
I'm writing similar code at the moment.
Chuck
On 3/6/13 11:28 PM, "Muthulingam Ammaiappan" <email@hidden>
wrote:
>Hi Friends,
>
>i had developed the custom list view which is having NSView as a cell with
>variable sizes to represent the video clips in the timeline.
>
>and i had implemented the drag and drop for reordering functionality...
>that is working as per the expectation...
>
>but i wanted to add the animation while doing the drag and drop like in
>"iPhoto"...
>
>(when user drag the item if the mouse co-ords enters the in between region
>then the corresponding elements will animate... and animation will end and
>it comeback its original position once the mouse left the coords)....
>
>here i am including the drag and drop code.... please help me how i can
>implement the above mentioned animation while doing drag and drop...
>
>
>Thanks & Regards,
>Muthu
>
>
>
>
>- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
>
>{
>
>NSDragOperation theOperation = NSDragOperationNone;
>
> self.highlightForDragAcceptance = YES;
>
>
>
>BOOL dropHighlight = _highlightForDragAcceptance;
>
>
>
>
>
> downLocation = [self convertPoint: [sender draggingLocation]
>fromView:
>[self superview]];
>
>
>
>
>
>
>
> dropindex = [self indexOfCellAtPoint:downLocation];
>
>
>
>
>
> theOperation = [timelineViewController validateDrop:sender proposedCell:
>dropindex
>
> proposedDropHighlight: dropHighlight];
>
>
>
>
> return theOperation;
>
>}
>
>
>- (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender
>
>{
>
>NSDragOperation theOperation = NSDragOperationNone;
>
> self.highlightForDragAcceptance = YES;
>
>
>
> BOOL dropHighlight = _highlightForDragAcceptance;
>
>
>
> currentLocation = [self convertPoint: [sender draggingLocation]
>fromView:
>[self superview]];
>
>
>
>
>
>
> NSUInteger _numberOfCells = [[timelineViewController collection]
>count];
>
> NSArray * sprites = [timelineViewController collection];
>
>
>
>
>
>
>
> dropindex = [self indexOfCellAtPoint:currentLocation];
>
>
>
>
>
>
>
> theOperation = [timelineViewController validateDrop:sender
>proposedCell:
>dropindex
>
> proposedDropHighlight: dropHighlight];
>
>
>
>
>
>return theOperation;
>
>}
>
>
>
>- (void)draggingExited:(id <NSDraggingInfo>)sender
>
>{
>
>#pragma unused(sender)
>
>
>
> self.highlightForDragAcceptance = NO;
>
>}
>
>
>- (BOOL)prepareForDragOperation:(id<NSDraggingInfo>)sender
>
>{
>
> sender.animatesToDestination = YES;
>
>
>
>return YES;
>
>}
>
>
>
>- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
>
>{
>
> BOOL highlight = _highlightForDragAcceptance;
>
>
>
>
>
>
>
>BOOL accepted = [timelineViewController acceptDrop:sender cellindex:
>dropindex dropHighlight:highlight];
>
> self.highlightForDragAcceptance = NO;
>
>
>
>return accepted;
>
>}
>
>
>
>- (void)concludeDragOperation:(id <NSDraggingInfo>)sender
>
>{
>
>#pragma unused(sender)
>
>}
>
>
>
>- (void)draggingEnded:(id <NSDraggingInfo>)sender
>
>{
>
>#pragma unused(sender)
>
> self.highlightForDragAcceptance = NO;
>
> [self deselectSelectedObjects];
>
>}
>
>
>
>
>- (BOOL)wantsPeriodicDraggingUpdates
>
>{
>
>return YES;
>
>}
>
>
>
>
>- (BOOL)writeCellsWithIndexes:(NSIndexSet*)indexes toPasteboard:(
>NSPasteboard *)dragPasteboard
>
>{
>
> [dragPasteboard declareTypes: [NSArray arrayWithObjects:
>NSStringPboardType, nil] owner: self];
>
>[dragPasteboard setString: @"Just Testing" forType: NSStringPboardType];
>
> return YES;
>
>
>}
>
>
>- (NSDragOperation)validateDrop:(id <NSDraggingInfo>)info proposedCell:(
>NSUInteger)index
>
> proposedDropHighlight:(BOOL)dropHighlight;
>
>{
>
>return NSDragOperationCopy;
>
>}
>
>
>- (BOOL)acceptDrop:(id <NSDraggingInfo>)info cellindex:(NSUInteger)index
>dropHighlight:(BOOL)dropHighlight
>
>{
>
> NSLog(@"Accept Drop");
>
> NSLog(@"selection index:%i",[spritesController selectionIndex]);
>
> NSLog(@"drop index:%i",index);
>
>
>
> MVSprite *temp = [collection objectAtIndex: [spritesController
>selectionIndex]];
>
>
>
> [spritesController
>removeObjectAtArrangedObjectIndex:[spritesController
>selectionIndex]];
>
> [spritesController insertObject:temp atArrangedObjectIndex:index];
>
>
>
>
>
>
>
> NSArray * sprites = [self collection];
>
>
> int count = [sprites count];
>
>
>
>
>//layout the subviews
>
>
> for (int i=0; i<count; i++)
>
> {
>
> MVSprite * current = [sprites objectAtIndex:i];
>
> if(i == 0)
>
> {
>
> current.start = 0;
>
> current.end = current.start + current.duration;
>
> [current setAnimate:YES];
>
> [current.spriteView setSpriteViewFrame];
>
>
>
> }else{
>
> MVSprite * previous = [sprites objectAtIndex:i-1];
>
>
>
> current.start = previous.end;
>
> current.end = current.start + current.duration;
>
> [current setAnimate:YES];
>
> [current.spriteView setSpriteViewFrame];
>
>
>
> }
>
>
>
> }
>
>}
>_______________________________________________
>
>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
_______________________________________________
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