【发布时间】:2018-01-25 05:18:30
【问题描述】:
所以我有一个名为currentEventImage 的UIImageView,它位于UIView blurryBackGround 中。我目前想在UIView 中居中UIImageView。以下是我当前的代码
//Subviews will be added here
view.addSubview(blurryBackGround)
view.addSubview(currentEventImage)
view.addSubview(currentEventDate)
//Constraints will be added here
_ = blurryBackGround.anchor(top: view.topAnchor, left: view.leftAnchor, bottom: nil, right: view.rightAnchor, paddingTop: 17, paddingLeft: 0, paddingBottom: 0, paddingRight: 0, width: self.view.frame.width, height: 330)
currentEventImage.heightAnchor.constraint(equalToConstant: 330).isActive = true
currentEventImage.topAnchor.constraint(equalTo: blurryBackGround.topAnchor, constant: 5).isActive = true
currentEventImage.center = blurryBackGround.center
blurryBackGround.addSubview(currentEventImage)
知道我会怎么做吗?
currentEventImage.center = blurryBackGround.convert(blurryBackGround.center, from: blurryBackGround.superview)
试过了,还是不行
【问题讨论】:
-
你检查过这个吗 - stackoverflow.com/a/11253622/4637057
-
你的意思是 2012 年使用的旧语法和过时的方法@VincentJoy
-
这不起作用@VincentJoy
-
请评论包含
heightAnchor和topAnchor的行并重试