English 中文(简体)
如何找到图像的确切轮换价值?
原标题:How to find the exact rotation value of an image?

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);

• 将所有轮换价值节省到一个阵列和营地;进行反射阵列和计算/最后的轮调价值

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);
}
}

现在,我写上了最后的轮值,即Xml文档,Close &重新启用,我能够读到XML文件的最后准确价值。

但是,由于最后的轮换价值不是实际的轮换价值,所以图像并非完全轮换到最后状态。

因此,我也尝试将硬编码价值和图像完全轮换。

self.transform = CGAffineTransformMakeRotation(1.57);//By 90 Degree

因此,如何找到准确的图像轮换价值。

问题回答

引言

In .h put this thing float angle;

-(void)viewDidLoad
{
[super viewDidLoad];

UIRotationGestureRecognizer *recognizer = [[[UIRotationGestureRecognizer alloc]                                          initWithTarget:self                                        action:@selector(handleRotate:)] autorelease];

[self.rotatedView addGestureRecognizer:recognizer];

}
- (void)handleRotate:(UIRotationGestureRecognizer *)recognizer {
    // current value is past rotations + current rotation
    float rotation = angle + -recognizer.rotation;  
    self.rotatedView.transform = CGAffineTransformMakeRotation(-rotation);

    // once the user has finsihed the rotate, save the new angle
    if (recognizer.state == UIGestureRecognizerStateEnded) {
        angle = rotation;

        NSLog(@"Last Rotation: %f",angle);
    }
}




相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签