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

このタイプを働きました。

右上の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に切り替えました。それはうまく動作します(時々)。

は編集:

これは、フレームの代わりに自動レイアウトを使用していますので、iOSの11で UIBarButtonItemの多くの開発者が直面する問題の

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

下記んようにあなたのコードでImageViewのの制約を追加することはできません賢明

その他、それはあなたの代わりにフレーム – iPatel

+0

感謝の自動レイアウトを使用する必要がありiOSの11の問題だ@iPatel 。画像ビューをナビゲーションバーに制約するか、高さと幅を設定するだけですか? – Cesare

+0

これは@iPatelを動作させます。返信として投稿することを自由に感じてください – Cesare

関連する問題