如何找到图像的精确旋转值?
目前我正在使用以下代码来旋转我的图像
- (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
那么应该如何解决才能获得图像的精确旋转值呢?
Currently i am using following code to rotate my image
- (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);
//Now i am saving all rotation value to an array & perform reverse array and fetching the //last rotation value
NSArray *reversedArray = [[arr reverseObjectEnumerator] allObjects];
NSLog(@"Array: %@", arr);
NSLog(@"Reversed Array: %@", reversedArray);
//Now the Reversed array is displaying always start with 0.0.....like value whatever may be the rotation Reversed Array: (
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);
}
}
Now i am writing the last rotation value to a xml file ,Close & restart app i am able to read the last exact value from XML file .
But as the last rotation value is not actual rotation value the image is not rotating perfectly to last state.
So i have also tried by putting hard coded value and the image rotating perfectly.
self.transform = CGAffineTransformMakeRotation(1.57);//By 90 Degree
So what should be the solution to get exact rotation value of image.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个
在 .h 里放这个东西
浮动角度;
Try this one
In .h put this thing
float angle;