Store mousedown locations

别等时光非礼了梦想. 提交于 2019-12-10 12:09:31

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!