2014-03-25 36 views
-1

我正在查看拍摄图像并旋转它以调用方法。下面的图片里面有一个戒指。我正在寻找的是在该图像上添加UIGestures,以允许它自由旋转,同时锁定在x和y轴上的位置。旋转它会导致不同的文字出现在中间。有点像转动表盘显示不同的选项。有没有什么好的教程来做这种事情?旋转UIImage调用iOS上的方法

enter image description here

回答

2

在尝试the tutorial on creating a dial control在雷Wenderlich。

创建的旋转效应的键是捕获触摸的视图和平移沿着xy轴运动到旋转(container要被旋转的图;你的图像视图,在这种情况下):

- (BOOL)beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event 
{ 
    // 1 - Get touch position 
    CGPoint touchPoint = [touch locationInView:self]; 
    // 2 - Calculate distance from center 
    float dx = touchPoint.x - container.center.x; 
    float dy = touchPoint.y - container.center.y; 
    // 3 - Calculate arctangent value 
    deltaAngle = atan2(dy,dx); 
    // 4 - Save current transform 
    startTransform = container.transform; 
    return YES; 
} 

- (BOOL)continueTrackingWithTouch:(UITouch*)touch withEvent:(UIEvent*)event 
{ 
    CGPoint pt = [touch locationInView:self]; 
    float dx = pt.x - container.center.x; 
    float dy = pt.y - container.center.y; 
    float ang = atan2(dy,dx); 
    float angleDifference = deltaAngle - ang; 
    container.transform = CGAffineTransformRotate(startTransform, -angleDifference); 
    return YES; 
} 
+0

虽然这个链接可能回答这个问题,但最好在这里包含答案的重要部分并提供参考链接。如果链接页面更改,则仅链接答案可能会失效。 –

+0

@KevinPanko好点。我添加了帖子中最相关的代码 – Austin