【问题标题】:CATransform3D rotate causes half of image to disappearCATransform3D 旋转导致一半图像消失
【发布时间】:2011-06-30 06:27:42
【问题描述】:

我正在使用以下代码来旋转图像,但是已经旋转“离开”页面的一半图像(沿 y 轴)消失了。怎么修? heading 以弧度表示。

    CALayer *layer = myUIImageView.layer;
    CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity;
    rotationAndPerspectiveTransform.m34 = 1.0 / 500;
    rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, heading, 0.0f, 1.0f, 0.0f);
    layer.transform = rotationAndPerspectiveTransform;

【问题讨论】:

  • 确实这似乎与 z-index 混淆了。这个 UIImageView 是一个 UIView 的一部分,它部分地“落后于”另一个 UIView,但在旋转之后,myUIImageView 总是绘制在顶部。

标签: iphone quartz-graphics transform calayer catransform3d


【解决方案1】:

解决方案是适当地设置我所有图层的zPosition 属性。感谢@Brad Larson,他在评论here 中提出了这个解决方案。看来,当您开始使用CATransform3D 时,addsubview 建立的正常zindex 视图层次结构被抛出了窗口。

【讨论】:

    【解决方案2】:
      layer.anchorPoint = CGPointMake(0.0, 0.0);
    

    【讨论】:

      【解决方案3】:

      anchorPoint 设置为{0.0, 0.0} 也可以(正如利亚姆已经指出的那样)。

      这里是完整的代码 sn-p 用于更改 anchorPoint 而不更改图层在屏幕上的位置:

           layer.anchorPoint = CGPointMake( 0.0, 0.0 );
      
           CGPoint position = layer.position;
           CGSize size = layer.bounds.size;
      
           CGFloat posX = position.x - size.width / 2.0;
           CGFloat posY = position.y - size.height / 2.0;
      
           layer.position = CGPointMake( posX, posY );
      

      【讨论】:

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