admin管理员组文章数量:1316661
If you configure simple Tip with MaxDisplayCount
option, this option doesn't have any effect when showing TipView
in SwiftUI view which is wrapped in UIHostingController
. The Tip never invalidates and remains visible until user dismisses it manually.
Tip definition:
struct CustomTip: Tip {
var title: Text {
Text("Tip title")
}
var message: Text? {
Text("Tip message")
}
var options: [Option] {
MaxDisplayCount(1)
}
}
AppDelegate:
import UIKit
import SwiftUI
import TipKit
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
try? Tips.configure()
let vc = UIHostingController(rootView: CustomView())
window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = vc
window?.makeKeyAndVisible()
return true
}
}
SwiftUI view:
import SwiftUI
import TipKit
struct CustomView: View {
var body: some View {
VStack {
TipView(CustomTip())
Text("Hello, World!")
}
}
}
If you configure simple Tip with MaxDisplayCount
option, this option doesn't have any effect when showing TipView
in SwiftUI view which is wrapped in UIHostingController
. The Tip never invalidates and remains visible until user dismisses it manually.
Tip definition:
struct CustomTip: Tip {
var title: Text {
Text("Tip title")
}
var message: Text? {
Text("Tip message")
}
var options: [Option] {
MaxDisplayCount(1)
}
}
AppDelegate:
import UIKit
import SwiftUI
import TipKit
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
try? Tips.configure()
let vc = UIHostingController(rootView: CustomView())
window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = vc
window?.makeKeyAndVisible()
return true
}
}
SwiftUI view:
import SwiftUI
import TipKit
struct CustomView: View {
var body: some View {
VStack {
TipView(CustomTip())
Text("Hello, World!")
}
}
}
Share
Improve this question
asked Jan 29 at 9:15
Lukáš MatuškaLukáš Matuška
11 bronze badge
2
- Isn't this the purpose of a Tip? The user have to manually close it. – Carsten Commented Jan 29 at 9:45
- Tips are heavily dependent on the SwiftUI environment, try moving the configure line into SwiftUI – lorem ipsum Commented Jan 29 at 11:49
1 Answer
Reset to default 0I filed a Feedback report and got an answer from Apple stating that this is known issue they are hoping to fix in a future update - claiming it is due to how SwiftUI APIs use scenePhase. Recommended solution for now is to use TipUIView instead of the TipView for displaying the tip.
本文标签: Swift TipKit MaxDisplayCount doesn39t work in UIHostingController on iOSStack Overflow
版权声明:本文标题:Swift TipKit MaxDisplayCount doesn't work in UIHostingController on iOS - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742007395a2412236.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论