So verwenden Sie FocusState in iOS 14 [Duplikat]IOS

Programmierung für iOS
Guest
 So verwenden Sie FocusState in iOS 14 [Duplikat]

Post by Guest »

Ich entwickle eine SwiftUI-App mit einem iOS-Mindestziel von 14 und stoße auf ein Problem mit FocusState, das erst ab iOS 15 verfügbar ist. Wie kann ich diesen Fehler beheben? Das ist meine Ansicht

Code: Select all

import SwiftUI

struct BaseInputOTP: View {
var isSecure: Bool = false
var isError: Bool = false
@Binding var value: String
@FocusState var focus: Bool

var body: some View {
HStack(spacing: 8) {
ForEach(0.. some View {
ZStack {
if value.count > index && !isSecure {
let startIndex = value.startIndex
let charIndex = value.index(startIndex, offsetBy: index)
let charToString = String(value[charIndex])

Text(charToString)
.font(FontFigtreeManager.heading5A)
.foregroundColor(Constants.ColorNeutralColorDark100)
} else {
Text(" ")
}
}
.padding(.horizontal, 18)
.padding(.vertical, 17)
.frame(maxWidth: .infinity, minHeight: 64, maxHeight: 64, alignment: .center)
.cornerRadius(Constants.RadiusMd)
.overlay {
let status = (focus && value.count == index)
let strokeColor = isError
? Color(red: 0.82, green: 0.26, blue: 0.26)
: Color(red: 0.1, green: 0.1, blue: 0.1).opacity(status ? 1 : 0.2)

RoundedRectangle(cornerRadius: Constants.RadiusMd)
.inset(by: 0.5)
.stroke(strokeColor, lineWidth: 1)
.animation(.easeInOut(duration: 0.2), value: isError)
.background (
Group{
if status {
BlinkingCursor()
}

}
)

if value.count > index && isSecure {
Circle()
.fill(Color(red: 0.1, green: 0.1, blue: 0.1))
.frame(width: 24, height: 24)
}
}
}
}

struct BlinkingCursor: View {
@State private var opacity: Double = 1.0

var body: some View {
Text("|")
.font(FontFigtreeManager.heading5A)
.foregroundColor(Color(red: 0.1, green: 0.1, blue: 0.1))
.opacity(opacity)
.onAppear {
withAnimation(Animation.linear(duration: 0.6).repeatForever(autoreverses: true)) {
opacity = 0.2
}
}
}
}

extension Binding where Value == String {
func limit(_ length: Int) -> Self {
if self.wrappedValue.count > length {
DispatchQueue.main.async {
self.wrappedValue = String(self.wrappedValue.prefix(length))
}
}
return self
}
}

Ich versuche zu suchen und zu fragen, aber alle sagen nur, dass ich mein Mindestziel auf 15 ändern soll. Ich kann das Mindestziel aufgrund von Kundenanforderungen nicht auf iOS 15 ändern. Wie kann ich meine Ansicht ändern, um die Fokusverwaltung auf eine Weise zu handhaben, die mit iOS 14 kompatibel ist?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post