i'm trying make app draws line on window reflects position of 2 touches on trackpad. here's code:
oh, quick note, startpoint , endpoint both cgpoint ivars. more me experimenting nstouches , core graphics, i'm not concerned following proper practices , not having ivars.
if user moves fingers enough, line fall behind. if user moves fingers enough long enough, can lift fingers , watch line continue move several seconds after user has stopped.code:- (void)drawrect:(nsrect)rect { cgcontextref mycontext = [[nsgraphicscontext currentcontext] graphicsport]; cgcontextsetlinecap(mycontext, kcglinecapsquare); cgcontextsetrgbstrokecolor(mycontext, 0.0, 0.0, 0.0, 1.0); cgcontextsetlinewidth(mycontext, 1.0); cgcontextmovetopoint(mycontext, startpoint.x + 0.5, startpoint.y + 0.5); cgcontextaddlinetopoint(mycontext, endpoint.x + 0.5, endpoint.y + 0.5); cgcontextstrokepath(mycontext); } - (void)touchesmovedwithevent:(nsevent *)event { nslog(@"touches moved."); nsmutableset *touches = [[event touchesmatchingphase:nstouchphaseany inview:self] mutablecopy]; nstouch *firsttouch = (nstouch *)[touches anyobject]; [touches removeobject:firsttouch]; nstouch *secondtouch = (nstouch *)[touches anyobject]; if (secondtouch) { float startx = (firsttouch.normalizedposition.x)*(self.frame.size.width); float starty = (firsttouch.normalizedposition.y)*(self.frame.size.height); startpoint = cgpointmake(startx, starty); float endx = (secondtouch.normalizedposition.x)*(self.frame.size.width); float endy = (secondtouch.normalizedposition.y)*(self.frame.size.height); endpoint = cgpointmake(endx, endy); [self setneedsdisplay:yes]; } }
suggestions?
edit: i'm running in debugger in xcode on original macbook air (1.6 ghz). so, shouldn't matter... i'd rather if aborted drawing missed in-between , skipped should right now.
dumb question, have tried :
code:if(![self needsdisplay]) [self setneedsdisplay:yes];
Forums Macs Mac Programming
- iPhone
- Mac OS & System Software
- iPad
- Apple Watch
- Notebooks
- iTunes
- Apple ID
- iCloud
- Desktop Computers
- Apple Music
- Professional Applications
- iPod
- iWork
- Apple TV
- iLife
- Wireless
No comments:
Post a Comment