티스토리 뷰

반응형

View Aligned Carousel Scrollview Paging

 

// https://developer.apple.com/documentation/swiftui/scrolltargetbehavior/viewaligned
/// 다음 뷰 약간 보이는 페이징 스크롤
struct ContentView: View {
    
    var items: [Color] = [.yellow, .green, .blue, .brown, .orange, .red]
    
    var body: some View {
        ScrollView(.horizontal) {
            LazyHStack(spacing: 20) {
                ForEach(items, id: \.self) { item in
                    item
                        .frame(width: 300, height: 300)
                }
            }
            .scrollTargetLayout() // <-
        }
        .scrollTargetBehavior(.viewAligned) // <-
        .contentMargins(20)
    }
}

iOS

Swift

Xcode

Objective-C

viewAligned

Carousel

Scrollview

Paging

scrollTargetBehavior

scrollTargetLayout

반응형
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
글 보관함