【问题标题】:swift - Translate a UIImageView on fix screen coordinate wth animationswift - 使用动画在修复屏幕坐标时翻译 UIImageView
【发布时间】:2017-12-03 15:51:08
【问题描述】:

我有一个 UIImageView 对象,它位于全屏屏幕的中心。我制作了一个动画,在相同的代码中执行缩放和平移。以下是源代码:

UIView.animate(withDuration: 1.0, animations: {
        let originalTransform = self.idImageView.transform
        let scaledTransform = originalTransform.scaledBy(x: 0.2, y: 0.2)
        let scaledAndTranslatedTransform = scaledTransform.translatedBy(x: 100, y: 100)
        self.idImageView.transform = scaledAndTranslatedTransform
    }, completion: { (finished) in
        self.animationCompeletedSuccessfully(finished)
    })

我希望我的 UIImageView 移动到 x=100 和 y=100 的坐标,但平移会将其相对于中心移动 100 点。我如何在窗口坐标系上翻译它? Apple Documentation of traslatedBy(x: , y:) 我读过这一篇,但无法清楚地了解协调系统

【问题讨论】:

    标签: ios swift animation uiviewanimation translate-animation


    【解决方案1】:

    假设您的imageview 中心有xy 坐标和widthheight。 您想要的目的地:destinationXdestinationY

    你的翻译应该是:

    • 作者:destinationX - x + width/2
    • 作者:destinationY - y + height/2

    记住,如果你做比例,你的widthheight应该乘以scaleRatio

    【讨论】:

    • 感谢您的回复。它正在部分工作。我不知道为什么。它使我的视线靠近预期的点。我不明白你的最后一行。你能解释一下吗?
    • 在您的情况下,它将是 destinationX - x + width/2 * 0.2y 相同
    • 请编辑你的代码如何实现它,然后我可以帮助你
    猜你喜欢
    • 2013-02-18
    • 2016-05-22
    • 1970-01-01
    • 2012-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-16
    • 2018-01-01
    相关资源
    最近更新 更多