1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【SwiftUI】公式 Tutorials「 Animating Views and Transitions」の解説Part.1

Last updated at Posted at 2021-02-15

この記事は何?

Section1「Add Hiking Data to the App」で作成するビューのコードを読んでみました。

環境

macOS 11.2.1
Xcode 12.4
Swift 5.3

HikeView

HikeViewの定義
struct HikeView: View {
    var hike: Hike
    @State private var showDetail = false

    var body: some View {
        VStack {
            HStack {
                HikeGraph(hike: hike, path: \.elevation)
                    .frame(width: 50, height: 30)
                    .animation(nil)

                VStack(alignment: .leading) {
                    Text(hike.name)
                        .font(.headline)
                    Text(hike.distanceText)
                }

                Spacer()

                Button(action: {
                    self.showDetail.toggle()
                }) {
                    Image(systemName: "chevron.right.circle")
                        .imageScale(.large)
                        .rotationEffect(.degrees(showDetail ? 90 : 0))
                        .padding()
                }
            }

            if showDetail {
                HikeDetail(hike: hike)
            }
        }
    }
}

HikeViewの外観
SwiftUI1.jpeg

HikeViewを構成するビュー階層
HikeView.001.png

状態変数showDetailの挙動

Button(action: {
    self.showDetail.toggle()                
}) {
    ...
}
if showDetail {
    HikeDetail(hike: hike)            
}

SwiftUI2.jpeg

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?