【问题标题】:How to get top-right and bottom-left coordinates of an image in UIImageView如何在 UIImageView 中获取图像的右上角和左下角坐标
【发布时间】:2017-04-24 23:10:51
【问题描述】:

我有一个 UIImageView,其图像为 AspectFit。我需要放置两个按钮,一个在右上角,另一个在左下角,如下图所示。

如何获取这些位置的图像坐标以正确放置按钮。

提前致谢。

【问题讨论】:

  • 试试UIImageView的AspectFill
  • @YunCHEN 只与 AspectFit 有关。

标签: ios swift swift3


【解决方案1】:

您可以使用AVFoundation 框架获得适合UIImageView 的图像矩形:

import AVFoundation ´

let fittedRect = AVMakeRect(aspectRatio: (image?.size)!, imageView.frame)
let height = fittedRect.height
let width = fittedRect.width

然后使用它来计算按钮位置(取决于您将按钮添加到哪个视图)。

【讨论】:

  • 使用originPoint.y + imageHeightoriginPoint.x + width
【解决方案2】:

我不知道它是否能解决你的问题,但我把那两个按钮就这样放了。

第 1 步:

在 imageView.Fixed 宽度和高度和中心对齐(这是您希望对齐)中的自动布局

第 2 步:

并将这两个按钮与此 imageView 对齐。

1.尾随

2.垂直间距

3.固定宽高

这样,这些按钮现在与图像对齐。

肖像

风景

【讨论】:

    猜你喜欢
    • 2021-10-30
    • 2011-04-14
    • 2013-12-22
    • 1970-01-01
    • 2012-09-13
    • 1970-01-01
    • 2016-10-18
    • 2018-12-29
    • 2017-05-13
    相关资源
    最近更新 更多