Привет,
Я озадачен тем, как и когда drawRect должен вызываться в подклассе NSCollectionView.
Я реализую операцию перетаскивания, чтобы перемещать NSCollectionViewItems в пределах коллекции, и хотел бы визуально указать, где закончится перетаскивание.
Подкласс не вызывает drawRect во время сеанса перетаскивания. (Это происходит во время прокрутки)
Это предполагаемая операция? Приветствуются любые подсказки о том, как правильно реализовать это поведение.
Полный проект xcode следующего кода доступен по адресу: http://babouk.ovh.org/dload/MyCollectionView.zip
С наилучшими пожеланиями
Обновление: код примера неверен. Вызов registerForDraggedTypes заставляет триггер коллекции drawRect, как и ожидалось.
Пример кода:
@interface CollectionViewAppDelegate : NSObject <NSApplicationDelegate>
{
NSWindow *window;
NSMutableArray *collectionContent;
}
/* properties declaration */
/* KVC compliance declarations */
@end
@interface MyCollectionView : NSCollectionView
@end
@interface ItemModel
{
NSString *name;
}
@property (copy) NSString *name;
@end
@implementation MyCollectionView
- (void)awakeFromNib {
[self registerForDraggedTypes:[NSArray arrayWithObjects:NSStringPboardType, nil]];
}
- (void)drawRect:(NSRect)rect {
NSLog(@"DrawRect");
}
- (void)mouseDragged:(NSEvent *)aEvent {
NSPoint localPoint = [self convertPoint:[aEvent locationInWindow] fromView:nil];
[self dragImage:[NSImage imageNamed:@"Move.png"]
at:localPoint
offset:NSZeroSize
event:aEvent
pasteboard:nil
source:self
slideBack:NO];
}
- (BOOL)prepareForDragOperation:(id < NSDraggingInfo >)sender {
return YES;
}
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender {
return NSDragOperationEvery;
}
- (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender {
[self setNeedsDisplay:YES];
return NSDragOperationEvery;
}
- (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal {
return NSDragOperationEvery;
}
- (void)mouseDown:(NSEvent *)theEvent {
}
@end
@implementation CollectionViewAppDelegate
@synthesize window, collectionContent, collectionView;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSMutableArray *data = [[NSMutableArray alloc] init];
/* Fill in data */
[self setCollectionContent:data];
[data release];
}
/* dealloc */
/* KVC implementation */
@end
@implementation ItemModel
@synthesize name;
/* dealloc */
@end