【发布时间】:2015-11-13 13:21:53
【问题描述】:
我有一个 UIView 并添加了一个 UIImageView 作为它的子项。我稍后通过另一个 UIButton 事件更改 UIView 的位置。
如果我更改 UIImageView 的图像 UIView - inc.所有盾牌 - 移回初始位置。
谁能解释一下这里发生了什么 :-D 我如何保持 UIView 的新位置?
Here a image screen I took to visualize the issue
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var number: UIImageView!
@IBOutlet weak var popup: UIView!
@IBAction func openPopup(sender: UIButton) {
self.popup.center = sender.center
//old position: (190.5, 124.0) - new Position: (173.0, 414.0)
}
@IBAction func updateImage(sender: UIButton) {
self.number.image = UIImage(named: "img-1")
}
}
更新:
我发现如果我停用自动布局,上面的代码可以工作。这是使用自动布局执行此操作的解决方案: Auto Layout center UIView above another UIView at its center
【问题讨论】:
标签: swift uiview uiimageview