Objective c 基于superview中的位置旋转UIView

Objective c 基于superview中的位置旋转UIView,objective-c,ipad,Objective C,Ipad,我有一个UIImageView,它是一个箭头图像。我将此视图添加到具有500x500尺寸的框架的父视图中。我希望旋转UIImageView,以便用户触摸并移动箭头时,箭头始终指向其父对象的中心 我在研究CG仿射变换和三角旋转,但我在开始时遇到了困难。有人能提供一些见解吗 谢谢 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]

我有一个UIImageView,它是一个箭头图像。我将此视图添加到具有500x500尺寸的框架的父视图中。我希望旋转UIImageView,以便用户触摸并移动箭头时,箭头始终指向其父对象的中心

我在研究CG仿射变换和三角旋转,但我在开始时遇到了困难。有人能提供一些见解吗

谢谢

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {    
    UITouch *touch = [touches anyObject];
    CGPoint point = [touch locationInView:self];

    pointerView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pointer.png"]];        
    pointerView.layer.anchorPoint = CGPointMake(0, 0.5);    
    pointerView.center = point;

    [self setPointerRotation];

    [self addSubview:pointerView];
    [pointerView release];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {    
    UITouch *touch = [touches anyObject];   
    CGPoint point = [touch locationInView:self];   

    pointerView.center = point;
    [self setPointerRotation];
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    [pointerView removeFromSuperview];
    pointerView = nil;
}

- (void)setPointerRotation {
    CGAffineTransform transform = // calculate rotation so that pointerView points to the center of the superview
    pointerView.transform = transform;
}