问题
My cocoa app calculates the location for every mousedown event. The next time the mouse is clicked, the location is overwritten by the new one. How can I store the locations? Is it possible to create an array with mousedown locations?
Thanks
回答1:
Sure you can. Since you're dealing with a primitive struct (NSPoint) you'll need to wrap that in an object before you can put it in an NSArray though. NSValue is a ready-made class that allows you to do this, take a look at [NSValue valueWithPoint:aPoint];
.
回答2:
It is possible. You could easily do something like this (assume storedLocations
is an ivar of type NSMutableArray
and has been properly initialized):
NSPoint thePoint = [theEvent locationInWindow];
[storedLocations addObject:[NSValue valueWithPoint:thePoint]];
来源:https://stackoverflow.com/questions/726133/store-mousedown-locations