2012-01-13 23 views
5

Làm thế nào để xoay UIImageView với hai fingure liên lạc trong iOS SDK..as Tôi biết điều này là rất đơn giản nhưng vì tôi sẽ là mới trong công nghệ này nên không thể hiểu ...UIRotationGestureRecognizer trên UIImageView

Làm thế nào để sử dụng UIRotationGestureRecognizer để thực hiện điều này ...

Vui lòng giúp tôi giải quyết vấn đề này ...

Cảm ơn.

+0

bạn đã làm gì cho đến nay? Bạn đã đọc hướng dẫn này chưa: http://developer.apple.com/library/ios/#documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/GestureRecognizers/GestureRecognizers.html#//apple_ref/doc/uid/TP40009541-CH6-SW1 – bandejapaisa

+0

bạn có thể tham khảo các liên kết sau, http://stackoverflow.com/questions/3448614/uiimageview-gestures-zoom-rotate-question, http://www.icodeblog.com/2010/10/14/working-with-uigesturerecognizers/ – rishi

Trả lời

12

Bộ luật này về xem đã tải hoặc ImageView tạo chức năng: m_ctrlImgVwShowImage - của bạn 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]; 
}