LoginSignup
2
2

More than 1 year has passed since last update.

SwiftUI開発サンプル(Preview,View加工,ViewAnimation)

Posted at

PreviewのResumeボタン押すのをショートカットキーでやるには?

この操作自体は
メニューバーのEditor -> Canvas -> Refresh Canvas
これでできます。

ショートカットキー(Key Bindings)には
command + option + p
デフォルトでこちらが割り当てられています。

PreviewのViewのサイズを小さくして要素の大きさに合わせる

.previewLayout(.sizeThatFits)

Viewの加工

Viewを丸でくり抜くには?
.clipShape(Circle())
Viewに影をつけるには?
.shadow(radius: )
Viewに丸い線を上に重ねる
.overlay {
    Circle().stroke(, lineWidth: )
}
組み合わせる
Text("Circle\nShadow\nOverlay")
    .frame(width: 100, height: 100)
    .foregroundColor(.white)
    .background(.blue)
    .clipShape(Circle())
    .shadow(radius: 7)
    .overlay {
        Circle().stroke(.white, lineWidth: 4)
    }

Viewのアニメーション

回転
.rotationEffect(.degrees(isOn ? 90 : 0))
拡大縮小
.scaleEffect(isOn ? 1.5: 1)
透明度
.opacity(isOn ? 1.0 : 0)
値の変更をwithAnimationブロックで囲うことでアニメーションする
@State private var isOn = false
...
wthAnimation {
    isOn.toggle()
}
Button {
    withAnimation {
        isOn.toggle()
    }
} label: {
    Text(">")
        .opacity(isOn ? 1.0 : 0.5)
        .rotationEffect(.degrees(isOn ? 90 : 0))
        .scaleEffect(isOn ? 0.8: 2.0)
        .padding()
}
2
2
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
2
2