2011-02-12 13 views
0

私はいくつかのhelp.How UIImageViewを画面でタップすると回転する必要がありますか?TapGestureでUIImageViewを回転

- (void)viewDidLoad { 

    UITapGestureRecognizer *tapgr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)]; 
    [self.view addGestureRecognizer:tapgr]; 
    [tapgr release];  
    [super viewDidLoad]; 
} 

    -(void)tap:(UITapGestureRecognizer *)gesture { 

    CGPoint touch = [gesture locationInView:self.view]; 
    CGPoint center = myImage.center; 
    float dx,dy,wtf; 
    dx = touch.x-center.x; 
    dy = touch.y-center.y; 
    wtf = atan2f(dy, dx); 

    [self rotateImage:self.myImage withAngle:wtf]; 
} 



    - (void)rotateImage:(UIImageView *)image withAngle:(float)newAngle 
{ 
image.transform = CGAffineTransformMakeRotation(newAngle); 


} 

- 間違いはどこですか?

答えて

1

私は私のコードとその作品の罰金

 
-(void)tap:(UITapGestureRecognizer *)gesture { 

    CGPoint p = [gesture locationInView:self.view]; 

    CGPoint zero; 
    zero.x = self.view.bounds.size.width/2.0; 
    zero.y = self.view.bounds.size.height/2.0; 

    CGPoint newPoint; 

    newPoint.x = p.x - zero.x; 
    newPoint.y = zero.y - p.y; 
    CGFloat angle; 
    angle = atan2(newPoint.x, newPoint.y); 
    self.myImage.transform = CGAffineTransformRotate(CGAffineTransformIdentity, angle); 

} 
を修正