小编Ika*_*Ika的帖子

如何在 SwiftUI 中使用超链接实现文本

在斯威夫特,如图所示在这里,你可以使用“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)

swiftui

18
推荐指数
6
解决办法
9401
查看次数

如何使用 SwiftUI 在多个屏幕上获取键盘高度并移动按钮

以下代码获取键盘显示时的键盘高度,并按键盘高度移动按钮。

此移动在转换源 (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)

iphone ios swift swiftui xcode11

9
推荐指数
1
解决办法
2484
查看次数

我想点击推送通知以在 SwiftUI 中打开特定屏幕

我正在使用 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)

push-notification apple-push-notifications swift swiftui

9
推荐指数
1
解决办法
1000
查看次数

如何使底部按钮跟随 SwiftUI 中的键盘显示

借助以下内容,我能够按照键盘显示屏上的按钮进行操作。但是,动画不能很好地应用。

如何在 SwiftUI 中显示键盘时显示完整列表

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)

swiftui

2
推荐指数
1
解决办法
1580
查看次数

点击 Firebase 动态链接不会调用 AppDelegate 中的应用程序 (_: continue: recoveryHandler :) 方法

使用 Firebase 动态链接,我希望能够单击链接以打开 iOS 应用程序。

该应用程序正在开发中,尚未在 AppStore 上架。

我是一边看文档一边设置的,但是即使点击链接启动了应用程序,也不会调用AppDelegate中的应用程序(_:continue:restoreHandler:)方法。

我按照以下步骤进行设置。有什么问题吗??

  1. 将“pod 'Firebase / DynamicLinks'”添加到 Podfile 并安装

  2. 打开 .xcworkspace 文件

  3. 创建动态链接“ https://XXXX.page.link/test

  4. 访问“ https://XXXX.page.link/apple-app-site-association

    {"applinks":{"apps":[],"details":[{"appID":"XXXXXXX.[Bundle ID]","paths":["NOT /_/ ","/ "]}] }}

  5. 创建用于动态链接的 URL 类型 在此处输入图片说明

  6. 启用“关联域”并添加“应用链接:XXXX.page.link” 在此处输入图片说明

  7. 如下实现 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)

firebase swift firebase-dynamic-links swiftui

2
推荐指数
1
解决办法
1634
查看次数