目前我正在使用以下代码来旋转我的图像
- (void)myImageRotate:(UIRotationGestureRecognizer *)gesture
{
if(arr==nil)
{
arr=[[NSMutableArray alloc] init ];
}
if ([gesture state] == UIGestureRecognizerStateBegan || [gesture state] == UIGestureRecognizerStateChanged)
{
currentRotation =(float) [gesture rotation];
self.transform=CGAffineTransformRotate(self.transform,currentRotation);
[gesture setRotation:0];
[arr addObject:[NSNumber numberWithFloat:currentRotation]];
}
NSLog(@"Rotation Value: %f", currentRotation);
//现在我将所有旋转值保存到一个数组并执行反向数组并获取 //最后一个旋转值
NSArray *reversedArray = [[arr reverseObjectEnumerator] allObjects];
NSLog(@"Array: %@", arr);
NSLog(@"Reversed Array: %@", reversedArray);
//现在显示的反转数组始终以 0.0 开头......无论可能是旋转反转数组的值如何:( 0, 0, "0.001174212", "0.006030798", "0.01210225", "0.01215386", "0.01220191 ", "0.01224673", "0.006139159", "0.006149054", "0.01850212", "0.01237607", )
lastRotationValue = 0.0;
for (NSString* stringValue in [arr reverseObjectEnumerator]) {
double value = [stringValue doubleValue];
if (value != 0.0) {
//Note: 1 degree=0.0174532925 radian
lastRotationValue = value;
break;
}
}
if (lastRotationValue != 0.0) {
NSLog(@"My firstNonZeroValue of Rotation Degree:%f",lastRotationValue);
}
}
现在我将最后一个旋转值写入一个 xml 文件,关闭并重新启动应用程序我能够从 XML 文件中读取最后一个精确值。
但是由于最后的旋转值不是实际的旋转值,图像并没有完美地旋转到最后的状态。
所以我也尝试过放置硬编码值和完美旋转的图像。
self.transform = CGAffineTransformMakeRotation(1.57);//By 90 Degree
那么获得图像精确旋转值的解决方案应该是什么。