2017-10-06 117 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