在斯威夫特,如图所示在这里,你可以使用“NSMutableAttributedString”在文本中嵌入的链接。
如何使用 SwiftUI 实现这一目标?
我按如下方式实现了它,但这看起来不像我想要的。
.
import SwiftUI
struct ContentView: View {
var body: some View {
HStack {
Text("By tapping Done, you agree to the ")
Button(action: {}) {
Text("privacy policy")
}
Text(" and ")
Button(action: {}) {
Text("terms of service")
}
Text(" .")
}
}
}
Run Code Online (Sandbox Code Playgroud) 以下代码获取键盘显示时的键盘高度,并按键盘高度移动按钮。
此移动在转换源 (ContentView) 和转换目标 (SecibdContentView) 处以相同方式执行,但按钮在转换目标处不移动。
如何使按钮在多个屏幕上移动相同?
import SwiftUI
struct ContentView: View {
@ObservedObject private var keyboard = KeyboardResponder()
var body: some View {
NavigationView {
VStack {
Text("ContentView")
Spacer()
NavigationLink(destination: SecondContentView()) {
Text("Next")
}
.offset(x: 0, y: -keyboard.currentHeight)
}
}
}
}
import SwiftUI
struct SecondContentView: View {
@ObservedObject private var keyboard = KeyboardResponder()
var body: some View {
VStack {
Text("SubContentView")
Spacer()
NavigationLink(destination: ThirdContentView()) {
Text("Next")
}
.offset(x: 0, y: -keyboard.currentHeight)
}
}
}
class KeyboardResponder: ObservableObject { …Run Code Online (Sandbox Code Playgroud) 我正在使用 SwiftUI。
我想通过单击推送通知来打开 Root View 以外的特定屏幕。有几种方法可以使用 StoryBoard 打开它,但不能没有 StoryBoard。
如何在不使用 StoryBoard 的情况下实现它?
我试过这个,但我是初学者,所以我不知道。
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
var window: UIWindow?
func userNotificationCenter(
_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions)
-> Void) {
completionHandler([.alert, .badge, .sound])
}
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: () -> Void) {
// I want to open a screen other than Root View here.
completionHandler()
}
... }
Run Code Online (Sandbox Code Playgroud) 借助以下内容,我能够按照键盘显示屏上的按钮进行操作。但是,动画不能很好地应用。
import SwiftUI
import Combine
import UIKit
class KeyboardResponder: ObservableObject {
let willset = PassthroughSubject<CGFloat, Never>()
private var _center: NotificationCenter
@Published var currentHeight: CGFloat = 0
var keyboardDuration: TimeInterval = 0
init(center: NotificationCenter = .default) {
_center = center
_center.addObserver(self, selector: #selector(keyBoardWillShow(notification:)), name: UIResponder.keyboardWillShowNotification, object: nil)
_center.addObserver(self, selector: #selector(keyBoardWillHide(notification:)), name: UIResponder.keyboardWillHideNotification, object: nil)
}
deinit {
_center.removeObserver(self)
}
@objc func keyBoardWillShow(notification: Notification) {
if let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
currentHeight = keyboardSize.height
guard let duration:TimeInterval …Run Code Online (Sandbox Code Playgroud) 使用 Firebase 动态链接,我希望能够单击链接以打开 iOS 应用程序。
该应用程序正在开发中,尚未在 AppStore 上架。
我是一边看文档一边设置的,但是即使点击链接启动了应用程序,也不会调用AppDelegate中的应用程序(_:continue:restoreHandler:)方法。
我按照以下步骤进行设置。有什么问题吗??
将“pod 'Firebase / DynamicLinks'”添加到 Podfile 并安装
打开 .xcworkspace 文件
创建动态链接“ https://XXXX.page.link/test ”
访问“ https://XXXX.page.link/apple-app-site-association ”
{"applinks":{"apps":[],"details":[{"appID":"XXXXXXX.[Bundle ID]","paths":["NOT /_/ ","/ "]}] }}
如下实现 AppDelegate
import UIKit
import Firebase
import FirebaseDynamicLinks
@UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
FirebaseApp.configure()
return true
}
// MARK: UISceneSession Lifecycle
func application(_ application: UIApplication, …Run Code Online (Sandbox Code Playgroud)