iOS 15에서 LazyVGrid 하위 요소의 높이가 일치하지 않는 문제점과 대책
iOS 15부터 버그로 인해 높이를 통일하지 못할 수 있습니다.
 
 StackOverflow에서도 같은 보고서가 있습니다.
Lazy VGrid로 해결하기 어려울 가능성이 높습니다.
이번에 Hstack을 이용해서
※ 이 코드는 대부분 우지 주이스 기사를 참고했습니다.
Preference Key와 minHeight를 이용해 문제를 잘 처리하는 것처럼 보인다.
그런 다음 iOS 14가 됩니다.5든 iOS 15든 다 움직인다.
 
 그러나 HStack은 LazyVGrid처럼 여러 데이터를 열로 배열하는 것을 만족시킬 수 없다.
여기에는 Laxy VGrid 의 배열이 아니라, 배열을 2 연속 Chunk화하는 것입니다.
예를 들어 Hstack에 2개씩 납품하는 방식으로 대응했다.
4
import SwiftUI
struct MaximumHeightPreferenceKey: PreferenceKey {
    static var defaultValue: CGFloat = 0
    static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) {
        value = max(value, nextValue())
    }
}
struct DetermineHeight: View {
    typealias Key = MaximumHeightPreferenceKey
    var body: some View {
        GeometryReader { proxy in
            Color.clear
                .anchorPreference(key: Key.self, value: .bounds) { anchor in
                    proxy[anchor].size.height
                }
        }
    }
}
struct ContentView: View {
    @State var maximumSubViewHeight: CGFloat = 0
    let columns: [GridItem] = Array(repeating: .init(.flexible()), count: 2)
    var body: some View {
        HStack {
            Group {
                Text("Hello")
                    .border(.red)
                    .overlay(DetermineHeight())
            }
            .frame(minHeight: maximumSubViewHeight, alignment: .bottom)
            Group {
                Text("Lorem\nipsum")
                    .border(.blue)
                    .overlay(DetermineHeight())
            }
            .frame(minHeight: maximumSubViewHeight, alignment: .bottom)
        }
        .border(.green)
        .padding(.horizontal, 100)
        .onPreferenceChange(DetermineHeight.Key.self) {
            maximumSubViewHeight = $0
        }
    }
}
struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
Reference
이 문제에 관하여(iOS 15에서 LazyVGrid 하위 요소의 높이가 일치하지 않는 문제점과 대책), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://zenn.dev/yoneapp/articles/02ed083e459c8e텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)