iphone - Drawing by finger move responding slow in iPad -
below code working responding slow, not draw fast finger movement. think subview “testview” cause of basic requirement of application.
in homeview.h file
iboutlet uiimageview *imgdraw; iboutlet uiview *testview; @private cgpoint currentpoint; cgpoint previouspoint1; cgpoint previouspoint2; here i’m using testview sub view in homeview draw within testview , here imgdraw existing within testview.
in homeview.m file
- (void)touchesmoved:(nsset *)touches withevent:(uievent *)event { mouseswiped = yes; uitouch *touch = [touches anyobject]; currentpoint = [touch locationinview:testview]; previouspoint2 = previouspoint1; previouspoint1 = [touch previouslocationinview:self.view]; currentpoint = [touch locationinview:self.view]; // calculate mid point. cgpoint mid1 = midpoint(previouspoint1, previouspoint2); cgpoint mid2 = midpoint(currentpoint, previouspoint1); uigraphicsbeginimagecontext(testview.frame.size); [imgdrawalphapad.image drawinrect:cgrectmake(0, 0, self.testview.frame.size.width, self.testview.frame.size.height)]; cgcontextsetlinecap(uigraphicsgetcurrentcontext(), kcglinecapround); //nslog(@"iphone"); //cgcontextsetlinewidth(uigraphicsgetcurrentcontext(), [appdelegate_iphone.strokewidth floatvalue]); cgcontextsetlinewidth(uigraphicsgetcurrentcontext(), 2); cgcontextsetrgbstrokecolor(uigraphicsgetcurrentcontext(), 1, 0, 0, 0.9); cgcontextbeginpath(uigraphicsgetcurrentcontext()); //code smooth drawing.{#dr#-12/05/2012} cgcontextmovetopoint(uigraphicsgetcurrentcontext(), mid1.x, mid1.y); // use quadcurve key cgcontextaddquadcurvetopoint(uigraphicsgetcurrentcontext(), previouspoint1.x, previouspoint1.y, mid2.x, mid2.y); cgcontextstrokepath(uigraphicsgetcurrentcontext()); //cgcontextflush(uigraphicsgetcurrentcontext()); drawimage.image = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext(); lastpoint = currentpoint; } cgpoint midpoint(cgpoint p1, cgpoint p2) { return cgpointmake((p1.x + p2.x) * 0.5, (p1.y + p2.y) * 0.5); }
Comments
Post a Comment