2

我有一个位于 UIScrollView 中的 UIImageView。我使用以下代码将图像加载到 UIImageView 的 CALayer 中:

UIImage *image = [UIImage imageNamed: fileToDisplay];    
NSLog(@"If I don't flip image imageScrollView.zoomScale: %f", imageScrollView.zoomScale);
[[imageView layer] setContents: (id)image.CGImage];
if (flipped)
{
    [[imageView layer] setTransform: CATransform3DMakeRotation(180.0 / 180.0 * M_PI, 0.0, 1.0, 0.0)];
    NSLog(@"If image flipped imageScrollView.zoomScale: %f", imageScrollView.zoomScale);
}

我正在围绕 y 轴“翻转”图像。意外事件是 imageView.layer 的转换正在更改 imageScrollView.zoomScale,如以下输出所示:

如果我不翻转图像 imageScrollView.zoomScale: 0.465455

如果图像翻转 imageScrollView.zoomScale: 1.000000

我的问题是如何让这不会发生?如果没有办法阻止这种行为,我必须做些什么来实现在我不翻转的图像上执行的图像框架。换句话说,仅将 zoomScale 设置为转换之前的值是行不通的。UIScrollView 中的其他内容发生了变化(不是 contentSize 或 contentOffset)。

谢谢您的帮助。

4

1 回答 1

0

因为您使用的是一种CATransform3DMake...方法,所以您正在创建一个新的转换并替换当前的转换。您需要改为使用CATransform3DRotate,将旋转添加到当前变换(用于缩放)。

imageView.layer.transform = CATransform3DRotate(imageView.layer.transform , 180.0 / 180.0 * M_PI, 0.0, 1.0, 0.0);
于 2015-11-05T19:20:27.763 回答