1

おはようございます !

写真のダウンロードと制約に関する設計上の質問があります。

現在、Haneke を使用してバックグラウンドで画像をダウンロードしています。それは魅力のように機能していますが、私が持つことができるさまざまな画像サイズ形式がたくさんあります (一度に 1 つの画像を表示します)。

だから私の問題は、さまざまなサイズに対応するために、比率に応じて画像を微調整することです。それは非常にうまくいっています:

 if let url = NSURL(string: coverPhoto.url) {

            self.coverImageView?.hnk_setImageFromURL(url,format: nil, failure: nil,success: { image in

                // Screen Width
                let screen_width = UIScreen.mainScreen().bounds.width

                // Ratio Width / Height
                let ratio =  image.size.height / image.size.width

                // Calculated Height for the picture
                let newHeight = screen_width * ratio

                self.__coverImageViewHeightLayoutConstraint?.constant = newHeight

                self.coverImageView?.image = image
            })
        }

プロトタイプ セルを使用してコンテンツを表示します。そのコードが完成したら、新しいレイアウトを適用/更新するためにカバー画像セルをリロードします。ここまでは順調ですね !!

しかし、私の問題は、画像がまったく見栄えが悪く、サイズが変更されている場合です。新しい制約が適用されるまでに少し時間がかかります。これにより、奇妙な/見栄えの悪いUIが発生することがわかります。 :=/

私が使用している他の方法は、単に画像を同期的にロードすることです:

                if let dataUrl = NSData(contentsOfURL: url)
            {
                let image = UIImage(data: dataUrl)

                // Screen Width
                let screen_width = UIScreen.mainScreen().bounds.width

                // Ratio Width / Height
                let ratio =  image!.size.height / image!.size.width

                // Calculated Height for the picture
                let newHeight = screen_width * ratio

                self.__coverImageViewHeightLayoutConstraint?.constant = newHeight

                self.coverImageView!.image = image!
            }

しかし、明らかに、パフォーマンス上の理由/スクロールの問題からそれを避けたいと思います(キャッシュされていないため、スクロールバックすると画像が再度ダウンロードされます)。

最善のアプローチは何ですか?

ありがとうございました !

4

0 に答える 0