每当编译我的应用程序时,我都会在 xcode 中看到以下警告消息。
iOS Simulator 部署目标“IPHONEOS_DEPLOYMENT_TARGET”设置为 8.0,但支持的部署目标版本范围为 9.0 到 14.3.99。
谷歌说它在某种程度上与 cocoapods 有关,但我没有使用它们(只是 swift 包)并且我也没有在 xcode 的项目文件列表中看到 pod 文件。
部署目标已设置为 14 -
关于如何摆脱这些消息有什么想法吗?
我无法摆脱我的 VStack 中的这个“前导”填充。
我将其父 VStack 的对齐方式设置为“前导”,但它仍然在左侧显示一些间距(对于文本和红色圆角矩形)。它们应该放置在屏幕截图中蓝色边缘旁边的左侧。
关于为什么这个填充出现在那里有什么想法吗?
这是代码:
import SwiftUI
struct RegisterView: View {
var body: some View {
VStack(spacing: 0) {
HStack(alignment: .top) {
Text("Register")
.font(.custom("NotoSans-Regular", size: 24))
.fontWeight(.bold)
.foregroundColor(Color.tertiaryTitleColor)
}
.frame(width: 299, height: 39)
.padding(.top, 78)
HStack(spacing: 13) {
BroviderButton(imageName: "googleLogo")
BroviderButton(imageName: "facebookLogo")
}
.padding(.top, 47)
VStack(alignment: .leading, spacing: 0) {
Text("Register with E-mail")
.font(.custom("NotoSans-Regular", size: 16))
RoundedRectangle(cornerRadius: 25)
.fill(Color.red)
.frame(width: 40, height: 20)
}
.frame(width: 279)
.padding(.top, 61)
Spacer()
}
.frame(maxHeight: /*@START_MENU_TOKEN@*/.infinity/*@END_MENU_TOKEN@*/)
.frame(maxWidth: /*@START_MENU_TOKEN@*/.infinity/*@END_MENU_TOKEN@*/)
.background(Color.loginBackgroundColor)
.ignoresSafeArea()
} …Run Code Online (Sandbox Code Playgroud) 我在尝试启动模拟器时收到以下消息
Details
Failed to re-create a coordinator for com.me.myapp.
Domain: IXErrorDomain
Code: 29
Failure Reason: Coordinator already exists.
User Info: {
FunctionName = "+[IXAppInstallCoordinator(IXSimpleInstaller) _beginInstallForURL:consumeSource:options:completion:]_block_invoke";
SourceFileLine = 313;
}
--
System Information
macOS Version 10.15.5 (Build 19F101)
Xcode 12.3 (17715) (Build 12C33)
Timestamp: 2021-01-25T15:50:20+01:00
Run Code Online (Sandbox Code Playgroud)
我还发现如果我在另一个设备模拟器上启动它,它可以正常工作(假设是 iphone 11 pro 而不是 12 pro),但我想以某种方式解决这个问题。
我已经尝试过的:
Xcode:版本 12.3 (12C33)
任何关于如何修复它的想法将不胜感激
我使用此代码来隐藏导航栏和后退按钮,但是当加载视图时,我仍然可以看到后退按钮一小会儿,然后它就消失了。有什么办法可以阻止它被显示吗?
var body: some View {
NavigationView {
NavigationLink(destination: DeferView { WeekView(journey: self.launcher.completeJourney!) }, isActive: self.$launcher.readyJourney ) { EmptyView () }
.navigationBarHidden(true)
.navigationBarTitle("")
}
}
Run Code Online (Sandbox Code Playgroud)
先感谢您,
当用户通过 FB 登录按钮完成授权时,我使用 Coordinator(符合 LoginButtonDelegate)对象来接收用户数据(配置文件、名称)。Coordinator().userId 属性使用用户 ID 进行更新,但我需要将其向上传递 1 级到 LoginView 并更新名为 thisSession 的环境对象(以某种方式使 thisSession.userId = Coordinator().userId )。
有什么办法可以做到这一点吗?我尝试使用 ObservableObject/Published 属性,但无法从协调器更新父对象的属性。
另一个想法是订阅 Auth.auth() 更改,但它似乎太复杂并且有点“老派”解决方案。我缺少一些简单的方法。
有什么提示/想法吗?
import SwiftUI
import FirebaseCore
import FirebaseAuth
import FBSDKLoginKit
import FBSDKCoreKit
struct LoginView: View {
@EnvironmentObject var thisSession: CurrentSession
@ObservedObject var mainData = MainViewModel()
var facebookView = facebook()
var body: some View {
VStack {
facebookView.frame(width: 240, height: 50)
Text("\(self.thisSession.userId ?? "none")")
}
}
}
struct LoginView_Previews: PreviewProvider {
static var previews: some View {
LoginView().environmentObject(CurrentSession()) …Run Code Online (Sandbox Code Playgroud) 我想知道为什么 SwiftUI 中的两个元素之间会出现这种间距?以及如何控制/修改它?我尝试向 ExtractedView 添加一些填充,但它没有改变任何内容。看起来它是由.frame(height: 56)引起的,但这正是按钮的高度,所以它不应该导致任何间距。
代码:
import SwiftUI
struct FirstLaunchView: View {
var body: some View {
VStack {
ZStack {
Image("first-launch")
.resizable()
.scaledToFill()
.frame(height: 483)
Text("AppName")
.font(.custom("Lobster", size: 24))
.fontWeight(.bold)
.foregroundColor(.white)
.frame(height: 483, alignment: .top)
.offset(x: 0, y: 61)
}
ZStack {
VStack {
ExtractedView(title: "Start", textColor: Color.secondaryColor, bgColor: Color.primaryColor)
ExtractedView(title: "Log in", textColor: Color.primaryColor, bgColor: Color.secondaryColor)
}
}
Spacer()
}
.ignoresSafeArea()
}
}
struct ExtractedView: View {
var title: String
var textColor: Color
var bgColor: …Run Code Online (Sandbox Code Playgroud) 当我在物理设备上关闭应用程序时,我遇到了奇怪的错误消息。我在模拟器中做了同样的事情,但没有发生这样的事情。
还尝试设置“事件引发”断点,但 XCode 说“无法在 0x1b3a7edd0 处为断点 4.2 设置断点站点:”
关于什么可能导致这种情况的任何想法?
2021-04-08 20:40:15.985908+0200 GoMom[21503:2008470] [SwiftUI] Invalid frame dimension (negative or non-finite).
2021-04-08 20:40:15.986074+0200 GoMom[21503:2008470] [SwiftUI] Invalid frame dimension (negative or non-finite).
2021-04-08 20:40:15.990231+0200 GoMom[21503:2008470] *** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan nan]. Layer: <CALayer:0x2824151a0; position = CGPoint (2 8); bounds = CGRect (0 0; 595 4); delegate = <UIView: 0x114d07cc0; frame = (2 8; 595 4); anchorPoint = (0, 0); autoresizesSubviews = NO; layer = …Run Code Online (Sandbox Code Playgroud) 我希望将这个红色矩形重新定位到左下角,但由于某种原因,我的对齐和填充没有按预期工作。我在做什么错以及如何将其移动到左下角?
代码:
struct ContentView: View {
var body: some View {
ZStack {
VStack(spacing: 0) {
Rectangle()
.fill(Color.red)
.frame(width: 197, height: 163)
}
.frame(width: 284, height: 269)
.padding(.leading, 0)
.padding(.bottom, 0)
.background(Color.blue)
}
}
}
Run Code Online (Sandbox Code Playgroud)
我创建了一个新的子视图,其中包含其他视图的标题。它有一个箭头图标,我想将一个闭包传递给这个子视图(profileClose 是一个函数):
PlainHeader(title: getLocalizedText("edit profile"), action: profileClose)
Run Code Online (Sandbox Code Playgroud)
问题是我希望这个闭包是可选的。所以我决定将它包装起来,() ? = nil但在我每次使用时都这样做之后PlainHeader(...)。Xcode 说"Extra argument 'action' in call"
import SwiftUI
struct PlainHeader: View {
var title: String
let action: (() -> Void)? = nil
var body: some View {
VStack(spacing: 0) {
ZStack {
VStack(spacing: 0) {
HStack {
Image("arrow-back")
.resizable()
.scaledToFit()
.frame(width: 18, height: 7)
.padding(.leading, 31)
Spacer()
}
.onTapGesture {
print("[debugUI] action called")
if self.action != nil {
self.action!()
}
}
}
VStack {
HStack …Run Code Online (Sandbox Code Playgroud)