Iphone 如何继续旋转图像

Iphone 如何继续旋转图像,iphone,Iphone,有一个按钮,我想在单击按钮时将图像旋转180度,但它仅在我第一次单击按钮时起作用,如何继续旋转图像,提前感谢? 以下是我的源代码: - (IBAction)touchButton_Refresh { photo *photos = [photoArray objectAtIndexhotoIndex]; NSData *xmlData = [NSData dataWithContentsOfFilehotos.localPath]; UIImage *image; if ([xmlData i

有一个按钮,我想在单击按钮时将图像旋转180度,但它仅在我第一次单击按钮时起作用,如何继续旋转图像,提前感谢? 以下是我的源代码:

- (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];


} 

您必须连接变换,否则只需继续应用相同的旋转(而不是实际旋转更多)。因此,替换这些行:

CGAffineTransform rotation = CGAffineTransformMakeRotation(3.14159265);
[slideItemRotate.photoImageView setTransform:rotation];
为此:

CGAffineTransform rotation = CGAffineTransformConcat([[slideItemRotate photoImageView] transform], CGAffineTransformMakeRotation(3.14159265));
[slideItemRotate.photoImageView setTransform:rotation];
这实际上将连接旋转并保持图像旋转。如果你总是在180度左右,另一种方法是测试身份转换。如果视图的变换是标识变换,请应用旋转。如果不是,则将转换重置为标识转换(有效地反转过程)