2017-10-06 118 views
2

我设置一个正常的图像视图作为我的导航栏项目自定义视图,但是这是它的发生:导航栏自定义图像视图问题11

let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 34, height: 34)) 
imageView.kf.setImage(with: user.profilePictureURL) 
if user.profilePictureURL == nil { 
    imageView.image = #imageLiteral(resourceName: "ProfilePlaceholderSuit") 
} 
imageView.backgroundColor = .white 
imageView.layer.masksToBounds = true 
imageView.layer.cornerRadius = 17 
imageView.layer.borderWidth = 1 
imageView.layer.borderColor = UIColor.white.cgColor 
imageView.isUserInteractionEnabled = true 
imageView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(handleTap))) 
navigationItem.rightBarButtonItem = UIBarButtonItem(customView: imageView) 
print("ok, so the image view frame is", imageView.frame) // 0, 0, 34, 34 

enter image description here

回答

1

这类型所面临的诸多开发商由于iOS中11 UIBarButtonItem问题,使用自动布局而不是帧。

所以你只是想设置右上barButton项目然后please check my answer.配置文件图像。

其他明智的,你可以在你的代码像下面

let widthConstraint = imageView.widthAnchor.constraint(equalToConstant: 34) 
    let heightConstraint = imageView.heightAnchor.constraint(equalToConstant: 34) 
    heightConstraint.isActive = true 
    widthConstraint.isActive = true 
0

这是Kingfisher框架存在问题。我已经切换到SDWebImage并且它工作正常(有时)。

编辑:

这个工作

let imageView = UIImageView() 
imageView.translatesAutoresizingMaskIntoConstraints = false 
imageView.heightAnchor.constraint(equalToConstant: 34).isActive = true 
imageView.widthAnchor.constraint(equalToConstant: 34).isActive = true 
+1

不,这不是与翠鸟框架问题补充ImageView的的限制,它的IOS 11的问题,您应该使用的,而不是框架 – iPatel

+0

由于自动布局@iPatel 。我是否必须将图像视图限制到导航栏或者只是设置其高度和宽度? – Cesare

+0

这工作@iPatel。随意张贴,作为回答 – Cesare