iphone - How To Rotate an UIImageView based on a point in Touches Moved Method? -


dear all,

i want rotate uiimageview relative point in touchesmoved method.

i tried 2 -3 methods not getting exact result expected be.

first method used

cgaffinetransform transforms = cgaffinetransformmakerotation(m_pi/2);  imgview.transform = transforms; 

this written in touchesmoved. expect rotation image view in each touchesmoved. rotation occuring once .

second method used was

cgaffinetransform transforms = cgaffinetransformrotate(imgview.transform, m_pi/2);  imgview.transform = transforms; 

now result image in image view continusely rotating in each move. imageview not rotating. need rotate imageview not image.

any appreciated.

thanks & best regards, rupesh r menon

if understood correctly want achieve single finger rotation on image. if can use following functions 1 of live working project. can use single image multiple images. need modify @ extend multiple images. best way extend uiimageview class , create own class.

from touches moved call function

  • [self transformimagewithtouches:touch];

declare 1 property , synthesize follows. (also please declare other variables if required in below code.

  • @property (nonatomic) cgfloat fltrotatedangle;
-(void)transformimagewithtouches:(uitouch *)touchlocation {     //nslog(@"before %f",self.fltrotatedangle);     cgpoint touchlocationpoint = [touchlocation locationinview:[self superview]];      cgpoint previoustouchlocationpoint = [touchlocation previouslocationinview:[self superview]];     cgpoint origin;     origin.x=self.center.x;     origin.y=self.center.y;     cgpoint previousdifference = [self vectorfrompoint:origin topoint:previoustouchlocationpoint];     cgaffinetransform newtransform =cgaffinetransformscale(self.transform, 1, 1);      cgfloat previousrotation = atan2(previousdifference.y, previousdifference.x);      cgpoint currentdifference = [self vectorfrompoint:origin topoint:touchlocationpoint];      cgfloat currentrotation = atan2(currentdifference.y, currentdifference.x);     cgfloat newangle = currentrotation- previousrotation;       //calculate angle store     flttmpangle = flttmpangle+newangle;     self.fltrotatedangle = (flttmpangle*180)/m_pi;        newtransform = cgaffinetransformrotate(newtransform, newangle);     [self animateimageview:self toposition:newtransform];    }  -(void)animateimageview:(uiimageview *)theview toposition:(cgaffinetransform) newtransform {     [uiview setanimationsenabled:yes];     [uiview beginanimations:nil context:null];     [uiview setanimationcurve:uiviewanimationcurvelinear];     [uiview setanimationbeginsfromcurrentstate:yes];     [uiview setanimationduration:0.0750];        self.transform = newtransform;     [uiview commitanimations]; }  -(cgpoint)vectorfrompoint:(cgpoint)firstpoint topoint:(cgpoint)secondpoint {     cgfloat x = secondpoint.x - firstpoint.x;     cgfloat y = secondpoint.y - firstpoint.y;      cgpoint result = cgpointmake(x, y);      return result; } 

hope helps. if stuck please let me know ll you.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -