Reputation: 43
In my UIView the User can place different UIImages. The User can move and rotate these images.
The Images, type, position are saved in a array for later restore.
I also want to save the ration degree.
Is it possible to read out the degree of the rotated images ? Or must I save the degree at the moment when the images are rotated ?
thanks
Upvotes: 0
Views: 47
Reputation: 43
@TheEye: not realy. I think in the link there is the solution. but I'm to stupid to adapt it to my app....
Here is the code where the rotation is done and saved but i works not very fine.
- (IBAction)rotateImage:(UIRotationGestureRecognizer *)sender {
snap = 0;
NSMutableDictionary *itemDSNew = [[NSMutableDictionary alloc] init];
NSDictionary *itemDSOld = (NSDictionary *)[messestandItems objectAtIndex:aktivItemID];
if (messestandItems.count > 2) {
CGFloat netRotation = [[itemDSOld objectForKey:@"rotation"] floatValue];
CGFloat rotation = [(UIRotationGestureRecognizer *)sender rotation];
CGAffineTransform transform = CGAffineTransformMakeRotation(rotation+netRotation);
aktivImageView.transform = transform;
if (sender.state==UIGestureRecognizerStateEnded) {
netRotation += rotation;
}
[itemDSNew addEntriesFromDictionary:itemDSOld];
[itemDSNew setObject:[NSString stringWithFormat:@"%f", aktivImageView.center.x] forKey:@"posX"];
[itemDSNew setObject:[NSString stringWithFormat:@"%f", aktivImageView.center.y] forKey:@"posY"];
[itemDSNew setObject:[NSString stringWithFormat:@"%f", rotation + netRotation] forKey:@"rotation"];
[itemDSNew setObject:[NSString stringWithFormat:@"0"] forKey:@"snap"];
[messestandItems replaceObjectAtIndex:aktivItemID withObject:itemDSNew];
[messestandItems writeToFile:[self saveFilePath] atomically:YES];
}
}
this is my code to rotate 45°:
float rad = M_PI * (float)45 / 180.0;
aktivImageView.transform = CGAffineTransformRotate(aktivImageView.transform, rad);
but what is the code when i later in the app want to know the transform (rad)
something like:
rad = aktivImageView.transform;
float degree = rad * 180 / M_PI;
and then i have the degree which the User had rotated the Image ?
Upvotes: 0
Reputation: 9346
Just remember the rotation at the moment when it is rotated - why make it more complicated than that?
Upvotes: 1