如何继续旋转图像
有一个按钮,当我点击按钮时,我想旋转图像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度旋转,另一种方法是测试身份变换。如果视图的变换是标识变换,则应用旋转。如果不是,则将转换重置为标识转换(有效地反转进程)。
以上是 如何继续旋转图像 的全部内容, 来源链接: utcz.com/qa/257291.html