【问题标题】:Transform of UIImageView.layer affects UIScrollView zoomScaleUIImageView.layer 的变换影响 UIScrollView zoomScale
【发布时间】:2012-07-23 16:04:13
【问题描述】:

我有一个位于 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)。

感谢您的帮助。

【问题讨论】:

    标签: ios uiscrollview uiimageview transform calayer


    【解决方案1】:

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

    imageView.layer.transform = CATransform3DRotate(imageView.layer.transform , 180.0 / 180.0 * M_PI, 0.0, 1.0, 0.0);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多