[ad_1]
I need to implement a abstract splash display screen on the finish of the scene. Though, I am undecided what to incorporate in my code that will enable that to occur. I’m on the lookout for an answer to including a splash display screen when the progress bar reaches 100%. Here is my code beneath…
struct QuestionView: View {
@State var present = false
@State var showSheet: Bool = false
@State var showSheetA: Bool = false
@State var showSheet2: Bool = false
@State personal var correctAnswer = 0
@State personal var choiceArray: [Int] = [0, 1, 2, 3]
@State personal var firstNumber = 0
@State personal var secondNumber = 0
@State personal var issue = 100
@State personal var rating: Double = 0.1
@State personal var Background1 = "Background 1"
@State personal var Background2 = "Background 2"
@State personal var Background3 = "Background 3"
@State personal var Background4 = "Background 4"
@State personal var Background5 = "Background 5"
@State personal var Background6 = "Background 6"
@State personal var Background7 = "Background 7"
@State personal var Background8 = "Background 8"
@State personal var Background9 = "Background 9"
@State personal var Background10 = "Background 10"
@State personal var Background11 = "Background 11"
@State personal var Background12 = "Background 12"
@State personal var background = [
"Background 1",
"Background 2",
"Background 3",
"Background 4",
"Background 5",
"Background 6",
"Background 7",
"Background 8",
"Background 9",
"Background 10",
"Background 11",
"Background 12",
]
@State var worth = "0"
let buttons: [[CalcButton]] = [
[.clear, .negative, .percent, .divide],
[.seven, .eight, .nine, .multiply],
[.four, .five, .six, .subtract],
[.one, .two, .three, .add],
[.zero, .decimal, .equal]
]
@State var currentOperation: Operation = .none
@State var runningNumber = 0
@State var levels : Double = 0
var physique: some View {
ZStack {
Picture("(Background1)")
.resizable()
.aspectRatio(contentMode: .fill)
.edgesIgnoringSafeArea(.all)
.blur(radius: 20)
.onAppear {
shuffle()
}
VStack {
VStack(alignment: .main) {
HStack {
HStack {
Circle()
.trim(from: 0.01, to: CGFloat(rating))
.stroke(LinearGradient(gradient: Gradient(colours: [Color.white, Color.white.opacity(0.2)]), startPoint: .topLeading, endPoint: .bottomTrailing), fashion: StrokeStyle(lineWidth: 17.5, lineCap: .spherical))
.shadow(radius: 8)
.rotationEffect(.levels(90))
.rotation3DEffect(Angle(levels: 180), axis: (x: 1, y: 0, z: 110))
.body(width: 60, peak: 60)
.animation(.easeOut)
.padding()
.padding([.top, .leading])
Spacer()
}
Button {
showSheet.toggle()
} label: {
VStack {
ZStack {
Rectangle()
.fill(.thinMaterial)
.body(width: 80, peak: 40)
.cornerRadius(30)
.padding(.prime, 13)
.padding(.trailing, 0)
HStack {
Picture(systemName: "circle.grid.3x3.fill")
.foregroundColor(.white)
.font(.title3)
.padding(.prime, 13)
.padding(.trailing, 0)
}
}
Textual content("CALCULATOR")
.font(.system(dimension: 11))
.padding(.trailing, 0)
}
}
.halfSheet(showSheet: $showSheet) {
ZStack {
Colour.black.opacity(0.925).ignoresSafeArea()
VStack {
Spacer()
// Textual content show
HStack {
Spacer()
Textual content(worth)
.daring()
.font(.system(dimension: 70))
.foregroundColor(.white)
.minimumScaleFactor(0.5)
}
.padding(.main)
.padding([.top, .trailing], 23)
.padding(.backside, 2)
// Our Buttons
ForEach(buttons, id: .self) { row in
HStack(spacing: 12) {
ForEach(row, id: .self) { merchandise in
Button {
self.didTap(button: merchandise)
} label: {
Textual content(merchandise.rawValue)
.font(.system(dimension: 36))
.body(width: self.buttonWidth(merchandise: merchandise), peak: 55)
.scaledToFit()
.background(merchandise.buttonColor)
.foregroundColor(.white)
.cornerRadius(95)
}
}
}
.padding(.backside, 0.55)
.padding([.leading, .trailing], 20)
}
}
}
}
Button {
showSheet2.toggle()
} label: {
VStack {
ZStack {
Rectangle()
.fill(.thinMaterial)
.body(width: 80, peak: 40)
.cornerRadius(30)
.padding(.prime, 13)
.padding(.trailing, 28.5)
HStack {
Picture(systemName: "guide")
.foregroundColor(.white)
.font(.title3)
.padding(.prime, 13)
.padding(.trailing, 28.5)
}
}
Textual content("DICTIONARY")
.font(.system(dimension: 11))
.padding(.trailing, 25.5)
}
}
.halfSheet(showSheet: $showSheet2) {
ZStack {
Dwelling()
}
}
}
.padding(.prime, 50)
}
VStack {
Textual content("Resolve the next:")
.foregroundColor(.white)
.font(.title2)
.fontWeight(.medium)
.padding(.backside, 24)
Textual content("(firstNumber) + (secondNumber)")
.foregroundColor(.white)
.font(.system(dimension: 60, design: .rounded))
.fontWeight(.medium)
.padding(.backside, 28)
.onAppear {
generateAnswers()
}
VStack(alignment: .heart, spacing: 0.01) {
LazyVGrid(columns: [GridItem(.adaptive(minimum: 150), spacing: 2.5)]) {
ForEach(0..<4, id: .self) { index in
Button {
answerIsCorrect(reply: choiceArray[index])
generateAnswers()
} label: {
AnswerButton(quantity: choiceArray[index])
}
}
}
Spacer()
}
HStack {
Button {
} label: {
ZStack {
Rectangle()
.fill(Colour.white.opacity(0.5))
.body(maxWidth: 150, maxHeight: 50)
.cornerRadius(15)
.padding([.leading, .trailing])
Picture(systemName: "chevron.left")
.font(.title)
}
}
Button {
showSheetA.toggle()
} label: {
VStack {
ZStack {
Rectangle()
.fill(Colour.white.opacity(0.5))
.body(maxWidth: 150, maxHeight: 50)
.cornerRadius(15)
.padding([.leading, .trailing])
Picture(systemName: "xmark")
.font(.title)
.foregroundColor(.crimson)
}
}
}
ZStack {
Rectangle()
.fill(Colour.white.opacity(0.5))
.body(maxWidth: 150, maxHeight: 50)
.cornerRadius(15)
.padding([.leading, .trailing])
Picture(systemName: "chevron.proper")
.font(.title)
}
}
.padding(.trailing, 6)
.padding(.backside)
Spacer(minLength: 65)
}
}
}
}
func shuffle() {
Background1 = background[Int.random(in: background.indices)]
Background2 = background[Int.random(in: background.indices)]
Background3 = background[Int.random(in: background.indices)]
Background4 = background[Int.random(in: background.indices)]
Background5 = background[Int.random(in: background.indices)]
Background6 = background[Int.random(in: background.indices)]
Background7 = background[Int.random(in: background.indices)]
Background8 = background[Int.random(in: background.indices)]
Background9 = background[Int.random(in: background.indices)]
Background10 = background[Int.random(in: background.indices)]
Background11 = background[Int.random(in: background.indices)]
Background12 = background[Int.random(in: background.indices)]
}
func answerIsCorrect(reply: Int) {
let isCorrect = reply == correctAnswer ? true : false
if isCorrect {
self.rating += Double(0.2)
} else {
self.rating = rating
}
}
func generateAnswers() {
firstNumber = Int.random(in: 0...(issue/2))
secondNumber = Int.random(in: 0...(issue/2))
var answerList = [Int]()
correctAnswer = firstNumber + secondNumber
for _ in 0...2 {
answerList.append(Int.random(in: 0...issue))
}
answerList.append(correctAnswer)
choiceArray = answerList.shuffled()
}
func didTap(button: CalcButton) {
change button {
case .add, .subtract, .multiply, .divide, .equal:
if button == .add {
self.currentOperation = .add
self.runningNumber = Int(self.worth) ?? 0
} else if button == .subtract {
self.currentOperation = .subtract
self.runningNumber = Int(self.worth) ?? 0
} else if button == .multiply {
self.currentOperation = .multiply
self.runningNumber = Int(self.worth) ?? 0
} else if button == .divide {
self.currentOperation = .divide
self.runningNumber = Int(self.worth) ?? 0
} else if button == .equal {
let runningValue = self.runningNumber
let currentValue = Int(self.worth) ?? 0
change self.currentOperation {
case .add:
self.worth = "(runningValue + currentValue)"
case .subtract:
self.worth = "(runningValue - currentValue)"
case .multiply:
self.worth = "(runningValue * currentValue)"
case .divide:
self.worth = "(runningValue / currentValue)"
case .none:
break
}
}
if button != .equal {
self.worth = "0"
}
case .clear:
self.worth = "0"
case .decimal, .%, .unfavourable:
break
default:
let quantity = button.rawValue
if self.worth == "0" {
worth = quantity
} else {
self.worth = "(self.worth)(quantity)"
}
}
}
func buttonWidth(merchandise: CalcButton) -> CGFloat {
if merchandise == .zero {
return ((UIScreen.important.bounds.width - (4*12)) / 4) * 2
}
return (UIScreen.important.bounds.width - (5*12)) / 4
}
func buttonHeight() -> CGFloat {
return (UIScreen.important.bounds.peak - (5*12)) / 4
}
}
Thanks for my code. I stay up for the very best answer.
[ad_2]
