2012-01-13 13 views
5

Come ruotare UIImageView con due fingure tocco in iOS SDK..as So che questo è molto semplice, ma a causa di io sono nuovo in questa tecnologia in modo riesco a capire ...UIRotationGestureRecognizer su UIImageView

Come utilizzare UIRotationGestureRecognizer per implementare questo ...

Ti prego, aiutami a risolvere questo problema ...

Grazie.

+0

Cosa hai fatto finora? Hai letto questa guida: http://developer.apple.com/library/ios/#documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/GestureRecognizers/GestureRecognizers.html#//apple_ref/doc/uid/TP40009541-CH6-SW1 – bandejapaisa

+0

tu? può fare riferimento ai seguenti link, http://stackoverflow.com/questions/3448614/uiimageview-gestures-zoom-rotate-question, http://www.icodeblog.com/2010/10/14/working-with-uigesturerecognizers/ – rishi

risposta

12

codice presente in mostra è stato caricato o l'imageview creare funzioni: m_ctrlImgVwShowImage - il tuo di imageview

UIRotationGestureRecognizer *rotationRecognizer = [[[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotate:)] autorelease]; 
    [rotationRecognizer setDelegate:self]; 
    [m_ctrlImgVwShowImage addGestureRecognizer:rotationRecognizer]; 

//lastRotation is a cgfloat member variable 

-(void)rotate:(id)sender { 
    if([(UIRotationGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) { 
     _lastRotation = 0.0; 
     return; 
    } 

    CGFloat rotation = 0.0 - (_lastRotation - [(UIRotationGestureRecognizer*)sender rotation]); 

    CGAffineTransform currentTransform = m_ctrlImgVwShowImage.transform; 
    CGAffineTransform newTransform = CGAffineTransformRotate(currentTransform,rotation); 

    [m_ctrlImgVwShowImage setTransform:newTransform]; 

    _lastRotation = [(UIRotationGestureRecognizer*)sender rotation]; 
}