을 탭하면 페이드 애니메이션 및 지연으로 즐겨 찾기 를 Toggle Text
숨기거나 표시해야합니다 . 또는 화면에 텍스트가 표시되는 동안 애니메이션을 좀주세요. 몇 가지 애니메이션 방법을 시도했지만 지금까지 작동하지 않습니다 . 다음은 코드입니다. Text
struct ContentView: View {
@State var showText: Bool
var body: some View {
VStack() {
Spacer()
Image(systemName: "star.fill")
if self.showText {
// Changing selection value.
Text("Favorites")
.font(.custom("Helvetica Neue", size: 20))
.animation(Animation.easeOut(duration: 2.0).delay(0.5))
}
Spacer()
.frame(height: 50)
Button(action: {
self.showText.toggle()
}) {
Text("Toggle Text")
}
Spacer()
}
.padding(5)
.font(.custom("Helvetica Neue", size: 14))
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView(showText: false)
}
}
가능한 접근 방식은 다음과 같습니다 (Xcode 11.2 / iOS 13.2에서 테스트 및 작동)
참고 : 미리보기는 전환을 처리 할 때 좋지 않으므로 시뮬레이터 또는 실제 장치로 테스트하십시오.
struct ContentView: View {
@State var showText: Bool = false
var body: some View {
VStack() {
Spacer()
Image(systemName: "star.fill")
if self.showText {
// Changing selection value.
Text("Favorites")
.font(.custom("Helvetica Neue", size: 20))
.transition(.opacity) // << transition works in add/remove view
}
Spacer()
.frame(height: 50)
Button(action: {
withAnimation(Animation.easeOut(duration: 2.0).delay(0.5)) {
self.showText.toggle() // << transition requires explicit animation
}
}) {
Text("Toggle Text")
}
Spacer()
}
.padding(5)
.font(.custom("Helvetica Neue", size: 14))
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다