2012-01-13 10 views
5

Cómo rotar UIImageView con dos fingure toque en IOS SDK..as Sé que esto es muy simple, pero debido a que soy nuevo en esta tecnología por lo que no puedo entender ...UIRotationGestureRecognizer en UIImageView

Cómo utilizar UIRotationGestureRecognizer a implementar esta ...

me puede ayudar a resolver este problema ...

Gracias.

+0

¿Qué has hecho hasta ahora? ¿Ha leído esta guía ?: http://developer.apple.com/library/ios/#documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/GestureRecognizers/GestureRecognizers.html#//apple_ref/doc/uid/TP40009541-CH6-SW1 – bandejapaisa

+0

usted puede referirse a los siguientes enlaces, http://stackoverflow.com/questions/3448614/uiimageview-gestures-zoom-rotate-question, http://www.icodeblog.com/2010/10/14/working-with-uigesturerecognizers/ – rishi

Respuesta

12

Código esto en vista de la carga tenía o la función de crear imageview: m_ctrlImgVwShowImage - su imageview de

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]; 
}