我如何在使用滚动视图的视图中消除此间隙。我不知道为什么会这样。您可以在图片中看到它。当我滚动其内容不会完全上升到顶部。总是有一点差距。我尝试了整理,但似乎没有任何办法解决我的问题。底部的代码对我来说是完整的View结构,因为我认为这可能对您有所帮助。
那是我的代码:
struct CommentView: View {
@EnvironmentObject var optionManager: OptionManager
@State private var showProfileView: Bool = false
@State private var imageTapped = false
var image: UIImage?
var body: some View {
ScrollView {
VStack(alignment: .leading) {
profileImage
tweetContent
tweetPostedTimeAgo
retweetAndLikeBar
optionsBar
}.padding([.horizontal, .top]) // Removing this does not solve the issue
Divider()
TweetListView(tweets: optionManager.finished ? optionManager.tweet.comments! : [])
}
.onAppear {
self.optionManager.getTweet()
}
.navigationBarTitle("Tweet")
}
private var profileImage: some View {
let user = optionManager.tweet.user!
return
HStack {
ImageLoaderView(imageURL: user.profileImageURL)
.frame(width: 50, height: 50)
.clipShape(Circle())
.sheet(isPresented: $showProfileView) {
ProfileView(profileUser: user)
.environmentObject(ProfileManager(userID: user.userID, fetchingMode: .user(mode: .tweets)))
}
.onTapGesture {
self.showProfileView = true
}
namesPortion
}
}
private var namesPortion: some View {
let user = optionManager.tweet.user!
return VStack {
Text(user.name).bold()
Text("@" + user.username)
.font(.subheadline)
.foregroundColor(Color.gray)
}
}
private var tweetContent: some View {
VStack(alignment: .leading) {
Text(optionManager.tweet.content).lineLimit(nil)
if image != nil {
Image(uiImage: image!)
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: UIScreen.main.bounds.width - 30)
.background(Color.clear)
.modifier(Rounded(cornerRadius: 10, lineWidth: 2, borderColor: .black))
.onTapGesture { self.imageTapped = true }
.sheet(isPresented: $imageTapped) {
TappedImageView(image: self.image!)
.environmentObject(self.optionManager)
}
}
}
}
private var tweetPostedTimeAgo: some View {
let formatter = DateFormatter()
formatter.locale = Locale(identifier: "DE-de")
formatter.dateFormat = "YYYY-MM-dd HH:mm:ss"
let date = formatter.date(from: optionManager.tweet.timestamp)
formatter.dateFormat = "HH:mm"
let tweetTime = formatter.string(from: date!)
formatter.dateFormat = "dd LLLL. YY"
let dateString = formatter.string(from: date!)
let littleCircle =
Circle()
.frame(width: 2, height: 2)
.background(Color.gray)
return
HStack(spacing: 5) {
Group {
Text(tweetTime)
littleCircle
Text(dateString)
littleCircle
Text("Twitter for iPhone")
.foregroundColor(.blue)
}
.foregroundColor(Color.gray)
.font(.subheadline)
}
}
private var retweetAndLikeBar: some View {
let tweet = optionManager.tweet
return VStack(alignment: .leading) {
Divider()
HStack(spacing: 10) {
HStack(spacing: 4) {
Text(tweet.retweets!.count.toString()).bold()
Text("Retweets").foregroundColor(.gray)
}
HStack(spacing: 4) {
Text(tweet.likes!.count.toString()).bold()
Text("""
„Gefällt mir"-Angaben"
""").foregroundColor(.gray)
}
}.font(.callout).padding(.leading, 2)
Divider()
}
}
private var optionsBar: some View {
Options(detailEnabled: false, imageURL: optionManager.tweet.postedImageURL)
.environmentObject(self.optionManager)
}
}