Objective c 使用轻触手势旋转UIImageView

Objective c 使用轻触手势旋转UIImageView,objective-c,ios4,ipad,Objective C,Ios4,Ipad,我需要一些帮助。如何通过点击屏幕旋转UIImageView - (void)viewDidLoad { UITapGestureRecognizer *tapgr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)]; [self.view addGestureRecognizer:tapgr]; [tapgr release]; [super

我需要一些帮助。如何通过点击屏幕旋转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);


}

不明白-哪里出错了?

我修复了我的代码,它工作正常

-(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); } -(无效)轻触:(UITapgestureRecognitor*)手势{ CGP点=[手势位置视图:self.view]; 零点; 零.x=self.view.bounds.size.width/2.0; 0.y=self.view.bounds.size.height/2.0; CGPoint-newPoint; newPoint.x=p.x-0.x; newPoint.y=0.y-p.y; CG浮动角; 角度=atan2(新点x,新点y); self.myImage.transform=CGAffineTransformRotate(CGAffineTransformity,角度); }