【问题标题】:How to detect a transform-only UIView?如何检测仅转换的 UIView?
【发布时间】:2018-06-07 03:12:15
【问题描述】:

UIStackView 是仅转换视图。这意味着无法对视图层执行操作。

是否有一种通用的方法来检测 UIView 是否是仅转换视图?

【问题讨论】:

    标签: ios swift uiview uikit


    【解决方案1】:

    实际上,仅转换视图是具有CATransformLayer 层的视图。

    所以问题应该是How to detect a UIView which has transform-only layer?,答案很简单,检查类的类型view.layer

    例如,当你想在stackView.layer上更改cornerRadius,它会通过类似的警告

    在仅变换层中更改属性cornerRadius,将无效

    这不是因为称为transform-only view 的东西,而是因为您正在更改CATransformLayer 上的cornerRadius,并且cornerRadius 属性根据Apple document for CATransformLayer 被忽略。

    仅渲染变换层的子层。图层渲染的CALayer属性被忽略,包括:背景颜色、内容、边框样式属性、描边样式属性等。

    你可能错的是可以在视图层上执行操作,但不是全部。

    如何检测UIView 是否为仅转换视图? - 使用下面的扩展

    extension UIView {
      func isTransformOnlyView() -> Bool {
        return self.layer.isKind(of: CATransformLayer.self)
      }
    }
    

    用法

    stackView.isTransformOnlyView()
    

    【讨论】:

      猜你喜欢
      • 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
      相关资源
      最近更新 更多