【问题标题】:Transform a Image in Swift 3在 Swift 3 中转换图像
【发布时间】:2017-09-22 21:48:54
【问题描述】:

所以我有一个简单的问题,我需要将 CALayer 旋转 90 度。然而,问题是,我从研究中发现的任何方法似乎都没有真正起到任何作用。下面是我使用的代码,其中 imgLayer 是 CALayer

var transform = CATransform3DIdentity
transform = CATransform3DRotate(transform, (CGFloat(Double.pi/2)), 0, 1, 0)
imgLayer.transform = transform

从我阅读的内容来看,这段代码应该可以工作,但它似乎根本没有任何影响,我想知道是否有人对为什么会这样有任何建议。非常感谢您对此主题的任何帮助,谢谢。

问候,尼克

【问题讨论】:

  • 您在 y 轴上旋转。您可能想要在 z 轴上旋转。
  • 非常感谢 Okan Yucel,您将我链接到的解决方案完美运行!

标签: swift image matrix transform


【解决方案1】:

您可以先在 imageView 中设置图像,然后在 imageView 中旋转获取图像

这里:

    let customImageView = UIImageView()
    customImageView.frame = CGRect.init(x: 0, y: 0, w: 250, h: 250)
    customImageView.image = UIImage(named: "yourImage")

    customImageView .transform = customImageView .transform.rotated(by: CGFloat.init(M_PI_2))
    var rotatedImage = UIImage()
    rotatedImage = customImageView.image!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-02
    • 2016-07-25
    • 2018-05-28
    • 2017-03-19
    • 2017-04-07
    • 1970-01-01
    • 2018-01-01
    • 1970-01-01
    相关资源
    最近更新 更多