用户个人资料的图片在旧版本上看起来很好(圆圈),但在我朋友的XR手机上看起来像一个椭圆形。我不知道为什么。下面是故事板约束的图片和我的约束代码。
Oval Shaped Profile Pic Storyboard constraints
@IBOutlet weak var profileButton: UIButton!var profile: Profile?
var imagePicker: UIImagePickerController!
var setImage = false
override func viewDidLoad() {
super.viewDidLoad()
profileButton.layer.cornerRadius = 0.5 * profileButton.bounds.size.width
profileButton.clipsToBounds = true
ProfileService.show { [weak self] (profile) in
self?.profile = profile
//display profile image and remove ninja default image
if let imageURL = URL(string: (profile?.imageURL ?? "")) {
if self?.setImage == false {
DispatchQueue.main.async {
self?.profileButton.setImage(nil, for: .normal)
self?.profileButton.kf.setBackgroundImage(with: imageURL, for: .normal)
self?.profileButton.layer.borderWidth = 0.5
self?.profileButton.layer.borderColor = UIColor.lightGray.cgColor
}
}
}else{
let image = UIImage(named: "ninja")
self?.profileButton.setImage(image, for: .normal)
}...
}
}
你给它冲突的约束。通过设置宽度以及前导和尾随偏移,当屏幕较宽时(在XR上)必须给出一些东西。自动布局显然选择打破宽度约束。
我建议摆脱前导和尾随约束,并将轮廓图片置于视图中心。
问题是您的前导和尾随约束。如果要使对象居中,请将其与视图的中心x约束对齐。进入的另一个好习惯是将1:1宽高比约束添加到您想要渲染为完美圆的任何对象。