我有一个self.photoView,它是UIView类型的,我有photoImageView,它是UIImageView。我想将photoImageView X和Y置于self.photoView中。使用Autolay约束在父视图中居中视图
此代码没有做任何事情!
let photoImageView = UIImageView.imageViewForPhotoTaken(self.photoView.bounds, image: img)
photoImageView.contentMode = UIViewContentMode.ScaleAspectFit
self.photoView.addSubview(photoImageView)
// set the autolayout constraints
self.photoView.addConstraint(NSLayoutConstraint(item: self.photoView, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: photoImageView, attribute: NSLayoutAttribute.CenterX, multiplier: 1.0, constant: 0))
调用的任何方法,我要对齐的子VI ew(photoImageView)中心水平和中心垂直。 –
您需要为这两个轴创建一个约束,并且很可能您还应该声明高度和宽度约束......您的代码不表示UIImageView应该是除0以外的任何大小 – Loxx
解决了您的问题? – HardikDG