我LoadingView使用SwiftUI 构建了一个用于在我从API提取远程数据时在应用程序中显示一些加载内容的功能。我正在使用Xcode 11.0 beta 5。
这是LoadingView:
struct LoadingView<Content>: View where Content: View {
@Binding var isShowing: Bool
var content: () -> Content
var body: some View {
GeometryReader { geometry in
ZStack(alignment: .center) {
self.content()
.disabled(self.isShowing)
.blur(radius: self.isShowing ? 3 : 0)
VStack {
Text("Loading...")
ActivityIndicator(isAnimating: .constant(true), style: .large)
}
.frame(width: geometry.size.width / 2,
height: geometry.size.height / 5)
.background(Color.white)
.foregroundColor(Color.primary)
.cornerRadius(5)
.opacity(self.isShowing ? 1 : 0)
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的数据存储。它被声明为ObservableObject具有多个@Published属性。它还从API进行一些远程获取:
class …Run Code Online (Sandbox Code Playgroud) 使用时我有一个奇怪的问题 monospacedDigitSystemFont(ofSize:weight:)
我有一个UISlider和一个UILabel在我的UIViewController.Label显示滑块的当前值+一些描述文本.更改滑块的值时,文本左右myLabel摇晃一下.myLabel因为我正在使用,我希望它的文字不会左右摇晃monospacedDigitSystemFont(ofSize:weight:).
这是我的代码:
import UIKit
class ExampleViewController: UIViewController {
@IBOutlet weak var myLabel: UILabel!
@IBOutlet weak var mySlider: UISlider!
override func viewDidLoad() {
super.viewDidLoad()
myLabel.font = UIFont.monospacedDigitSystemFont(ofSize: 15, weight: .bold)
}
@IBAction func sliderChanged(_ sender: UISlider) {
myLabel.text = String(format: "%.5f is the actual Value of the Slider", sender.value)
}
}
Run Code Online (Sandbox Code Playgroud)
关于摇晃的GIF:
有什么建议?我错过了什么吗?
当通过APN使用Apple的推送通知时,我们遇到了一个令人困惑的问题.我们有以下场景(非常标准我猜):
当我们的应用程序(我在这里称之为"MyApp")安装并启动时,我们第一次要求用户通过"MyApp"向他发送推送通知的权限.
在这个例子中,AppDelegate看起来像这样:
import UIKit
import UserNotifications
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Register Remote Notifications
UNUserNotificationCenter.current().delegate = self
self.registerForPushNotifications()
return true
}
// MARK: - Remote Notifications
func registerForPushNotifications() {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { (granted, error) in
guard granted else {
return
}
self.getNotificationSettings()
}
}
func getNotificationSettings() {
UNUserNotificationCenter.current().getNotificationSettings { (settings) in
guard settings.authorizationStatus == .authorized else {
return
}
DispatchQueue.main.async { …Run Code Online (Sandbox Code Playgroud) 概括:
当使用GMSMapView来自 GoogleMaps 框架的对象(从这里每个 pod 安装:https : //cocoapods.org/pods/GoogleMaps)时,我在将自定义地图样式应用于GMSMapView- 城市和国家标签正在消失 - 这不会当我不为地图使用任何自定义样式时,不会发生这种情况。(设置或不设置哪些 stlye 属性并不重要,它总是发生在我身上)
重现步骤:
我在只有一个 ViewController 的单视图应用程序中重现了我的问题,其中地图在 Storyboard 中受到约束并链接到我的 ViewController.swift。该应用程序如下所示:
应用委托:
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
let myGoogleMapsAPIKey: String = "[here goes my API-Key]"
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
GMSServices.provideAPIKey(self.myGoogleMapsAPIKey)
return true
}
func applicationWillResignActive(_ application: UIApplication) {}
func applicationDidEnterBackground(_ application: UIApplication) {}
func applicationWillEnterForeground(_ application: UIApplication) {}
func applicationDidBecomeActive(_ application: UIApplication) {}
func applicationWillTerminate(_ application: …Run Code Online (Sandbox Code Playgroud) 我正在尝试构建一个原型应用程序来评估 AWS-Amplify (DataStore) 在我们的下一个应用程序中的使用情况。我在尝试同步 2 个客户端时遇到问题。我按照此处教程的说明设置了 AWS-DataStore: https: //docs.amplify.aws/lib/datastore/getting-started/q/platform/ios使用 Cocoapods。关于 Cocoapods,一切都按预期进行。我尝试了一些测试,这些测试也可以在上面的“操作数据”链接下看到。我还做了“将数据同步到云”部分。我可以在 AWS 控制台的 dynamoDB 中查看我的数据。当我添加条目时,我可以在控制台中看到它,一切都按预期工作,但我在两种情况下遇到问题:
假设我有 2 个客户端 A 和 B(都运行 iOS 13 - 无论是真实设备还是模拟器),我希望这些客户端保持同步。为此,我添加了一个 PostStore(我使用 atm 上方 AWS 链接中的示例架构),如下所示:
import Foundation
import Combine
import SwiftUI
import Amplify
class PostStore: ObservableObject {
@Published private(set) var posts: [Post] = []
var postSubscription: AnyCancellable?
init() {
self.getAllPostsFromDataStore()
}
deinit {
self.unsubscribeFromDataStore()
}
func getAllPostsFromDataStore() {
Amplify.DataStore.query(Post.self) { (result) in
switch result {
case .success(let posts):
DispatchQueue.main.async {
print("Got \(posts.count) Posts from …Run Code Online (Sandbox Code Playgroud)