룰렛 뷰 추가
This commit is contained in:
40
SodaLive/Sources/FortuneWheel/FortuneWheel.swift
Normal file
40
SodaLive/Sources/FortuneWheel/FortuneWheel.swift
Normal file
@@ -0,0 +1,40 @@
|
||||
//
|
||||
// FortuneWheel.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 2023/12/07.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct FortuneWheel: View {
|
||||
|
||||
private let model: FortuneWheelModel
|
||||
@StateObject private var viewModel: FortuneWheelViewModel
|
||||
|
||||
public init(model: FortuneWheelModel) {
|
||||
self.model = model
|
||||
_viewModel = StateObject(wrappedValue: FortuneWheelViewModel(model: model))
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
ZStack(alignment: .top) {
|
||||
ZStack(alignment: .center) {
|
||||
SpinWheelView(data: (0..<model.titles.count).map { _ in Double(100 / model.titles.count) },
|
||||
labels: model.titles, colors: model.colors)
|
||||
.frame(width: model.size, height: model.size)
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: model.size / 2)
|
||||
.stroke(lineWidth: model.strokeWidth)
|
||||
.foregroundColor(model.strokeColor)
|
||||
)
|
||||
.rotationEffect(.degrees(viewModel.degree))
|
||||
.onAppear {
|
||||
viewModel.spinWheel()
|
||||
}
|
||||
SpinWheelBolt()
|
||||
}
|
||||
SpinWheelPointer(pointerColor: model.pointerColor).offset(x: 0, y: -25)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user