【发布时间】:2012-07-11 11:16:19
【问题描述】:
我有一个带有箭头图像的 UIImageView。当用户点击 UIView 时,这个箭头应该指向点击的方向,保持它的位置,它应该只是改变变换。我已经实现了以下代码。但它没有按预期工作。我添加了一个截图。在此屏幕截图中,当我触摸左上角时,箭头方向应如图所示。但事实并非如此。
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch=[[event allTouches]anyObject];
touchedPoint= [touch locationInView:touch.view];
imageViews.transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(rangle11));
previousTouchedPoint = touchedPoint ;
}
- (CGFloat) pointPairToBearingDegrees:(CGPoint)startingPoint secondPoint:(CGPoint) endingPoint
{
CGPoint originPoint = CGPointMake(endingPoint.x - startingPoint.x, endingPoint.y - startingPoint.y); // get origin point to origin by subtracting end from start
float bearingRadians = atan2f(originPoint.y, originPoint.x); // get bearing in radians
float bearingDegrees = bearingRadians * (180.0 / M_PI); // convert to degrees
bearingDegrees = (bearingDegrees > 0.0 ? bearingDegrees : (360.0 + bearingDegrees)); // correct discontinuity
return bearingDegrees;
}
【问题讨论】:
-
请告诉我们它没有按预期工作。箭头是否指向正确的方向?它是否围绕错误的轴旋转?
-
是的,它没有指向正确的方向。当我触摸 UIView 上的另一个点时,此箭头指向另一个方向。
-
您的图像指向哪个方向?起来了吗?
标签: ios cocoa-touch uiimageview transform image-rotation