You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
계속 진행하기 전에 한 가지 더 재미있는 것이 있는데, sheet에 텍스트를 눌러 sheet가 닫히게 하는 방법입니다.
아래로 스와이프를 할 수 있지만 때로는 프로그래밍 방식으로 뷰를 닫고 싶을 때가 있습니다.
예를 들어 버튼을 누르면 뷰가 사라지도록 할 수 있는 거죠. 는 이 작업을 수행하는 두 가지 방법을 제공하지만 가장 쉬운 방법은 다른 속성 래퍼를 사용하는 것입니다.
이것은 @Environment 이라고 불리고, 외부에서 우리에게 제공된 값을 저장하는 속성을 만들 수 있습니다.
쉽게 말해
사용자가 lightMode 입니까, DarkMode입니까?",
"더 작거나 더 큰 글꼴을 요구했습니까?",
"어떤 시간대에 있습니까?"
라는 변화에 제공된 값을 주는 것이죠. 이것을 사용해 보기 위해 SecondView에 presentationMode 을 넣어 보도록 하겠습니다.
코드는 위에 사용했던 코드를 그대로 가져와서 수정하도록 하겠습니다.
Text 가 있던 자리를 Button으로 수정해주고, 그에 self.presentationMode.wrappedValue.dismiss() 코드를 할당해 줘야 합니다.
self.presentationMode.wrappedValue.dismiss()
structSecondView:View{@Environment(\.presentationMode)varpresentationModevarname:Stringvarbody:someView{
//Text부분을 Button으로 바꿔주었다
Button("Your name is \(name)"){self.presentationMode.wrappedValue.dismiss()}}}
fullScreenCover
sheet와 유사하게 작동되는 수정자인 FullScreenCover
은 sheet와 동일하지만 이름 그대로 화면을 꽉 채워주는 시트라고 보면 됩니다. sheet와 한번 비교해보겠습니다.
Sheet
import SwiftUI
// MARK : Body
structContentView:View{@StatevarshowSheet:Bool=falsevarbody:someView{ZStack{Color("Peach").ignoresSafeArea()Button(action:{
showSheet.toggle()}){Text("시트").font(.title).foregroundColor(.black).padding().background(Color.white).cornerRadius(20).sheet(isPresented: $showSheet, content:{SecondView()})}}}}
// MARK : PrieView
structContentView_Previews:PreviewProvider{staticvarpreviews:someView{ContentView()}}
// MARK : SecondeView
structSecondView:View{@Environment(\.presentationMode)varpresentationModevarbody:someView{ZStack(alignment:.topLeading){Color("Paleblue").ignoresSafeArea()Button(action:{
presentationMode.wrappedValue.dismiss()}){Image(systemName:"xmark").font(.title).foregroundColor(.white).padding(20)}}}}
FullScreenCoverSWIFT
import SwiftUI
// MARK : Body
structContentView:View{@StatevarshowSheet:Bool=falsevarbody:someView{ZStack{Color("Peach").ignoresSafeArea()Button(action:{
showSheet.toggle()}){Text("시트").font(.title).foregroundColor(.black).padding().background(Color.white).cornerRadius(20).fullScreenCover(isPresented: $showSheet, content:{SecondView()})}}}}
// MARK : PrieView
structContentView_Previews:PreviewProvider{staticvarpreviews:someView{ContentView()}}
// MARK : SecondeView
structSecondView:View{@Environment(\.presentationMode)varpresentationModevarbody:someView{ZStack(alignment:.topLeading){Color("Paleblue").ignoresSafeArea()Button(action:{
presentationMode.wrappedValue.dismiss()}){Image(systemName:"xmark").font(.title).foregroundColor(.white).padding(20)}}}}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Sheet 란 ?
SwiftUI
에는 여러 가지view
를 보여주는 방법이 있습니다. 가장 기본적인 것 중 하나는sheet
입니다.이것은 기존 뷰 위에 새로운 뷰가 표시됩니다.
iOS에서는 자동으로 프레젠테이션을 제공하여 현재 뷰가 뒤쪽으로 빠지고 새로운 뷰가 맨 위 애니메이션으로 표시됩니다.
sheet(isPresented: )
는 Alert 와 코드가 유사합니다대신,
sheet
를 보여야 하는 조건을 정의하고, 그러한 조건이true
이거나false
가 되면sheet
가 각각 제시되거나 기각됩니다.sheet
에 트위터처럼@아이디
를 넣고 싶을 때는SecondView
에var name
을String
으로 정의해주고 텍스트를 바꿔줍니다.이제
ContentView
의sheet
부분도 수정해야 합니다.@Environment / presentationMode
SWIFT
계속 진행하기 전에 한 가지 더 재미있는 것이 있는데,
sheet
에 텍스트를 눌러sheet
가 닫히게 하는 방법입니다.아래로 스와이프를 할 수 있지만 때로는 프로그래밍 방식으로 뷰를 닫고 싶을 때가 있습니다.
예를 들어 버튼을 누르면 뷰가 사라지도록 할 수 있는 거죠.
는 이
작업을 수행하는 두 가지 방법을 제공하지만 가장 쉬운 방법은 다른 속성 래퍼를 사용하는 것입니다.이것은
@Environment
이라고 불리고, 외부에서 우리에게 제공된 값을 저장하는 속성을 만들 수 있습니다.쉽게 말해
사용자가 lightMode 입니까, DarkMode입니까?",
"더 작거나 더 큰 글꼴을 요구했습니까?",
"어떤 시간대에 있습니까?"
라는 변화에 제공된 값을 주는 것이죠. 이것을 사용해 보기 위해
SecondView
에presentationMode
을 넣어 보도록 하겠습니다.코드는 위에 사용했던 코드를 그대로 가져와서 수정하도록 하겠습니다.
Text
가 있던 자리를Button
으로 수정해주고, 그에self.presentationMode.wrappedValue.dismiss()
코드를 할당해 줘야 합니다.fullScreenCover
sheet와 유사하게 작동되는 수정자인 FullScreenCover
은 sheet와 동일하지만 이름 그대로 화면을 꽉 채워주는 시트라고 보면 됩니다. sheet와 한번 비교해보겠습니다.
Sheet
FullScreenCoverSWIFT
Beta Was this translation helpful? Give feedback.
All reactions