У меня есть 4 подсказки, которые нужно отобразить на экране, поэтому я создал такой
код:
struct TipContent {
let title: String
let message: String
}
// MARK: - TipKit Manager
class TipKitManager: ObservableObject {
static let shared = TipKitManager()
// All tip contents in a single array
let tipContents: [TipContent] = [
TipContent(title: "Welcome!", message: "Start your journey by logging in to your account."),
TipContent(title: "Enter Username!", message: "Provide your username or email to proceed."),
TipContent(title: "Enter Password!", message: "Use your secure password to log in safely."),
TipContent(title: "Register!", message: "Don't have an account? Tap Register to create one!")
]
@Published var currentTipIndex: Int = 0
@Published var showTip: Bool = true
var currentTip: LoginTip? {
guard showTip && currentTipIndex < tipContents.count else { return nil }
return LoginTip(index: currentTipIndex, content: tipContents[currentTipIndex])
}
var totalSteps: Int {
tipContents.count
}
var currentStep: Int {
currentTipIndex + 1
}
func moveToNextTip() {
if currentTipIndex < tipContents.count - 1 {
currentTip?.invalidate(reason: .tipClosed)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
self.currentTipIndex += 1
}
} else {
dismissTips()
}
}
func dismissTips() {
currentTip?.invalidate(reason: .tipClosed)
showTip = false
}
func resetTips() {
currentTipIndex = 0
showTip = true
}
}
// MARK: - Dynamic Tip
struct LoginTip: Tip {
let index: Int
let content: TipContent
var title: Text {
Text(content.title)
}
var message: Text? {
Text(content.message)
}
}
// MARK: - Custom Tip View Style (Refactored)
struct NewFeatureTipViewStyle: TipViewStyle {
let step: Int
let totalSteps: Int
var onNext: (() -> Void)? = nil
func makeBody(configuration: Configuration) -> some View {
VStack(alignment: .leading, spacing: 10) {
configuration.title
.font(.title2)
.bold()
configuration.message
.foregroundStyle(.secondary)
HStack {
// Progress dots
HStack {
ForEach(1...totalSteps, id: \.self) { i in
Capsule()
.fill(i == step ? .green : .gray.opacity(0.4))
.frame(width: 24, height: 6)
}
}
Spacer()
if step < totalSteps {
Button("Next") { onNext?() }
.foregroundStyle(.green)
} else {
Button("Done") {
configuration.tip.invalidate(reason: .tipClosed)
}
.foregroundStyle(.green)
}
}
.padding(.top, 10)
}
.padding(.vertical, 20)
.padding(.horizontal, 24)
}
}
Экран входа в систему: здесь я показываю подсказки, но сначала отображается 1-й вид подсказки, но здесь, если я нажму «Далее», он должен переместиться на 2-е место (текстовое поле электронной почты), но он закрывается.. не переходит на 2-е и все 4... где я ошибаюсь.. как исправить
struct LoginView: View {
@StateObject private var tipManager = TipKitManager.shared
var body: some View {
VStack(spacing: 30) {
// MARK: LOGIN HEADER
Text("Login")
.popoverTip(tipManager.currentTipIndex == 0 ? tipManager.currentTip : nil, arrowEdge: .top)
.tipViewStyle(
NewFeatureTipViewStyle(
step: tipManager.currentStep,
totalSteps: tipManager.totalSteps,
onNext: { tipManager.moveToNextTip() }
)
)
VStack(spacing: 20) {
// MARK: USERNAME
TextField("Enter email or username", text: $userName)
.textFieldStyle(.roundedBorder)
.popoverTip(tipManager.currentTipIndex == 1 ? tipManager.currentTip : nil, arrowEdge: .bottom)
.tipViewStyle(
NewFeatureTipViewStyle(
step: tipManager.currentStep,
totalSteps: tipManager.totalSteps,
onNext: { tipManager.moveToNextTip() }
)
)
// MARK: PASSWORD
SecureField("Password", text: $uaerPassword)
.textFieldStyle(.roundedBorder)
.popoverTip(tipManager.currentTipIndex == 2 ? tipManager.currentTip : nil, arrowEdge: .bottom)
.tipViewStyle(
NewFeatureTipViewStyle(
step: tipManager.currentStep,
totalSteps: tipManager.totalSteps,
onNext: { tipManager.moveToNextTip() }
)
)
// MARK: REGISTER
HStack {
Text("Don't have an account?")
.foregroundColor(.gray)
Text("Register here!")
.popoverTip(tipManager.currentTipIndex == 3 ? tipManager.currentTip : nil, arrowEdge: .top)
.tipViewStyle(
NewFeatureTipViewStyle(
step: tipManager.currentStep,
totalSteps: tipManager.totalSteps,
onNext: { tipManager.moveToNextTip() }
)
)
.onTapGesture {
isRegTapped = true
}
}
}
.padding()
Spacer()
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/798 ... ton-action
Все представления TipKit не отображаются при нажатии кнопки ⇐ IOS
Программируем под IOS
-
Anonymous
1761711449
Anonymous
У меня есть 4 подсказки, которые нужно отобразить на экране, поэтому я создал такой
код:
struct TipContent {
let title: String
let message: String
}
// MARK: - TipKit Manager
class TipKitManager: ObservableObject {
static let shared = TipKitManager()
// All tip contents in a single array
let tipContents: [TipContent] = [
TipContent(title: "Welcome!", message: "Start your journey by logging in to your account."),
TipContent(title: "Enter Username!", message: "Provide your username or email to proceed."),
TipContent(title: "Enter Password!", message: "Use your secure password to log in safely."),
TipContent(title: "Register!", message: "Don't have an account? Tap Register to create one!")
]
@Published var currentTipIndex: Int = 0
@Published var showTip: Bool = true
var currentTip: LoginTip? {
guard showTip && currentTipIndex < tipContents.count else { return nil }
return LoginTip(index: currentTipIndex, content: tipContents[currentTipIndex])
}
var totalSteps: Int {
tipContents.count
}
var currentStep: Int {
currentTipIndex + 1
}
func moveToNextTip() {
if currentTipIndex < tipContents.count - 1 {
currentTip?.invalidate(reason: .tipClosed)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
self.currentTipIndex += 1
}
} else {
dismissTips()
}
}
func dismissTips() {
currentTip?.invalidate(reason: .tipClosed)
showTip = false
}
func resetTips() {
currentTipIndex = 0
showTip = true
}
}
// MARK: - Dynamic Tip
struct LoginTip: Tip {
let index: Int
let content: TipContent
var title: Text {
Text(content.title)
}
var message: Text? {
Text(content.message)
}
}
// MARK: - Custom Tip View Style (Refactored)
struct NewFeatureTipViewStyle: TipViewStyle {
let step: Int
let totalSteps: Int
var onNext: (() -> Void)? = nil
func makeBody(configuration: Configuration) -> some View {
VStack(alignment: .leading, spacing: 10) {
configuration.title
.font(.title2)
.bold()
configuration.message
.foregroundStyle(.secondary)
HStack {
// Progress dots
HStack {
ForEach(1...totalSteps, id: \.self) { i in
Capsule()
.fill(i == step ? .green : .gray.opacity(0.4))
.frame(width: 24, height: 6)
}
}
Spacer()
if step < totalSteps {
Button("Next") { onNext?() }
.foregroundStyle(.green)
} else {
Button("Done") {
configuration.tip.invalidate(reason: .tipClosed)
}
.foregroundStyle(.green)
}
}
.padding(.top, 10)
}
.padding(.vertical, 20)
.padding(.horizontal, 24)
}
}
[b]Экран входа в систему:[/b] здесь я показываю подсказки, но сначала отображается 1-й вид подсказки, но здесь, если я нажму «Далее», он должен переместиться на 2-е место (текстовое поле электронной почты), но он закрывается.. не переходит на 2-е и все 4... где я ошибаюсь.. как исправить
struct LoginView: View {
@StateObject private var tipManager = TipKitManager.shared
var body: some View {
VStack(spacing: 30) {
// MARK: LOGIN HEADER
Text("Login")
.popoverTip(tipManager.currentTipIndex == 0 ? tipManager.currentTip : nil, arrowEdge: .top)
.tipViewStyle(
NewFeatureTipViewStyle(
step: tipManager.currentStep,
totalSteps: tipManager.totalSteps,
onNext: { tipManager.moveToNextTip() }
)
)
VStack(spacing: 20) {
// MARK: USERNAME
TextField("Enter email or username", text: $userName)
.textFieldStyle(.roundedBorder)
.popoverTip(tipManager.currentTipIndex == 1 ? tipManager.currentTip : nil, arrowEdge: .bottom)
.tipViewStyle(
NewFeatureTipViewStyle(
step: tipManager.currentStep,
totalSteps: tipManager.totalSteps,
onNext: { tipManager.moveToNextTip() }
)
)
// MARK: PASSWORD
SecureField("Password", text: $uaerPassword)
.textFieldStyle(.roundedBorder)
.popoverTip(tipManager.currentTipIndex == 2 ? tipManager.currentTip : nil, arrowEdge: .bottom)
.tipViewStyle(
NewFeatureTipViewStyle(
step: tipManager.currentStep,
totalSteps: tipManager.totalSteps,
onNext: { tipManager.moveToNextTip() }
)
)
// MARK: REGISTER
HStack {
Text("Don't have an account?")
.foregroundColor(.gray)
Text("Register here!")
.popoverTip(tipManager.currentTipIndex == 3 ? tipManager.currentTip : nil, arrowEdge: .top)
.tipViewStyle(
NewFeatureTipViewStyle(
step: tipManager.currentStep,
totalSteps: tipManager.totalSteps,
onNext: { tipManager.moveToNextTip() }
)
)
.onTapGesture {
isRegTapped = true
}
}
}
.padding()
Spacer()
}
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/79801765/all-tipkit-views-are-not-showing-with-button-action[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия