English 中文(简体)
迅速与URL一道展示KFImage UI - Kingfisher
原标题:Having trouble displaying KFImage with URL in SwiftUI - Kingfisher

I m目前正在开展一个快速倡议项目,并利用国王渔民图书馆展示图像。 然而,Im面临一个使用<代码>KFImage的图像显示问题,带有URL。

下面是我守则的简化版本:

import SwiftUI
import Kingfisher

struct TopMoviePreview: View {
    var movie: Movie
    
    func isCategoryLast(_ cat: String) -> Bool {
        let catCount = movie.categories.count
        
        if let index = movie.categories.firstIndex(of: cat) {
            if index + 1 != catCount {
                return false
            }
        }
        
        return true
    }
    
    var body: some View {
        ZStack {
            KFImage(URL(string:"https://picsum.photos/seed/picsum/200/300")!)
                .resizable()
                .scaledToFill()
                .clipped()
            
            VStack {
                Spacer()
                
                HStack {
                    ForEach(movie.categories, id: .self) { category in
                        
                        HStack {
                            Text(category)
                            .font(.footnote)
                            .foregroundColor(.black)
                            
                            if !isCategoryLast(category) {
                                Image(systemName: "circle.fill")
                                    .foregroundColor(.blue)
                                    .font(.system(size: 3))
                            }
                        }
                    }
                }
                
                HStack {
                    Spacer()
                    
                    SmallVerticalButton(text: "My List", isOnImage: "checkmark", isOffImage: "plus", isOn: true) {
                        //
                    }
                    
                    Spacer()
                    
                    WhiteButton(text: "Play", imageName: "play.fill") {
                        //
                    }
                    .frame(width: 120)
                    
                    Spacer()
                    
                    SmallVerticalButton(text: "Info", isOnImage: "info.circle", isOffImage: "info.circle", isOn: true) {
                        //
                    }
                    
                    Spacer()
                }
            }
            .background(
//                LinearGradient.blackOpacityGradient
//                    .padding(.top, 250)
            )
        }
        .foregroundColor(.white)
    }
}


#Preview {
    TopMoviePreview(movie: movie2)
}

The issue is that the image is not being displayed as expected. I have verified that the URL is correct, and if I replace it with a static image, it works fine. It seems to be related to the asynchronous loading of the image.

I have tried using different approaches, including checking if the URL is valid and force-unwrapping it, but the problem persists. The placeholder image is also not showing up.

如果对可能产生这一问题和我如何解决这一问题有任何见解或建议,将受到高度赞赏。

Thank you!

它没有显示任何形象的最新预览

“entergraph

最佳回答

这个问题并不涉及<代码>KFImage,而是涉及你的布局。 由于你对内容的看法是ZStack,它将自动填满整个屏幕或超声。 你还把VStack置于KFImage之上。 这一五位顶高度压倒了整个屏幕,有<条码>。 发表以下意见:<代码>.background,你将看到KFImage。

问题回答

暂无回答




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签