Hi, I'm doing a rotation of an image. I want to know how do I see the rotation value when I rotate? Thank you.
In header file:
in my main file:
I tried to add this line to see the rotation value
But the value sometimes changes to positive value or negative value, is currentAngle a radian?
How do I convert this value to degrees positive/negative value, or clockwise/counter clockwise degrees value? I'm kind of confuse now. Please help.
In header file:
Code:
static inline CGFloat angleBetweenLinesInRadians(CGPoint line1Start, CGPoint line1End, CGPoint line2Start, CGPoint line2End) {
CGFloat a = line1End.x - line1Start.x;
CGFloat b = line1End.y - line1Start.y;
CGFloat c = line2End.x - line2Start.x;
CGFloat d = line2End.y - line2Start.y;
CGFloat line1Slope = (line1End.y - line1Start.y) / (line1End.x - line1Start.x);
CGFloat line2Slope = (line2End.y - line2Start.y) / (line2End.x - line2Start.x);
CGFloat degs = acosf(((a*c) + (b*d)) / ((sqrt(a*a + b*b)) * (sqrt(c*c + d*d))));
return (line2Slope > line1Slope) ? degs : -degs;
}
in my main file:
Code:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
if ([touches count] == 2) {
NSArray *twoTouches = [touches allObjects];
UITouch *first = [twoTouches objectAtIndex:0];
UITouch *second = [twoTouches objectAtIndex:1];
CGFloat currentAngle = angleBetweenLinesInRadians([first previousLocationInView:self.view], [second previousLocationInView:self.view], [first locationInView:self.view], [second locationInView:self.view]);
label.transform = CGAffineTransformRotate(label.transform, currentAngle);
}
}
I tried to add this line to see the rotation value
Code:
[statusRotate setText:[NSString stringWithFormat:@"%d",currentAngle]];
How do I convert this value to degrees positive/negative value, or clockwise/counter clockwise degrees value? I'm kind of confuse now. Please help.
Last edited: