Reputation: 11
there is a button, I want to rotate the image for 180 when I click the button, but it only works when I first click the button, how to continue to rotate the image, thanks in advance? the following is my source code:
- (IBAction)touchButton_Refresh {
photo *photos = [photoArray objectAtIndexhotoIndex];
NSData *xmlData = [NSData dataWithContentsOfFilehotos.localPath];
UIImage *image;
if ([xmlData isKindOfClass:[NSData class]]) {
image = [[UIImage imageWithData:xmlData] retain];
}
SlideItem *slideItemRotate;
if (toOrientation == 1 || toOrientation == 2) {
slideItemRotate = [[SlideItem alloc] initWithFrame:CGRectMake(768*photoIndex, 0, 768, 980)];
}
else if (toOrientation == 3 || toOrientation == 4) {
slideItemRotate = [[SlideItem alloc] initWithFrame:CGRectMake(1024*photoIndex, 0, 1024, 700)];
}
slideItemRotate.photoImageView.image = image;
CGAffineTransform rotation = CGAffineTransformMakeRotation(3.14159265);
[slideItemRotate.photoImageView setTransform:rotation];
[[[slideScrollView subviews] objectAtIndex:0] removeFromSuperview];
[slideScrollView addSubview:slideItemRotate];
[slideItemRotate release];
}
Upvotes: 0
Views: 448
Reputation: 78393
You have to concatenate the tranform, otherwise you just keep applying the same rotation (not actually rotating it more). So, replace these lines:
CGAffineTransform rotation = CGAffineTransformMakeRotation(3.14159265);
[slideItemRotate.photoImageView setTransform:rotation];
with this:
CGAffineTransform rotation = CGAffineTransformConcat([[slideItemRotate photoImageView] transform], CGAffineTransformMakeRotation(3.14159265));
[slideItemRotate.photoImageView setTransform:rotation];
This will actually concatenate the rotation and keep the image rotating around. Another way to do it if you're always going around 180 degrees is to test for the identity transform. If the view's transform is the identity transform, apply the rotation. If not, reset the transform to the identity transform (effectively inverting the process).
Upvotes: 1