我是 SwiftUI 的新手。我有三个视图,我希望它们在 PageView 中。我想通过像页面浏览一样滑动来移动每个视图,我希望小点指示我所在的视图。
我正在使用新的 Xcode 12 beta 和 SwiftUi 2.0。.matchedGeometryEffect()修改器非常适合做英雄动画。@NamespaceSwiftUI 中引入了一个新属性。它超级酷。工作真棒。
我只是想知道是否有可能将命名空间变量传递给多个视图?
这是我正在研究的一个例子,
struct HomeView: View {
@Namespace var namespace
@State var isDisplay = true
var body: some View {
ZStack {
if isDisplay {
VStack {
Image("share sheet")
.resizable()
.frame(width: 150, height: 100)
.matchedGeometryEffect(id: "img", in: namespace)
Spacer()
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color.blue)
.onTapGesture {
withAnimation {
self.isDisplay.toggle()
}
}
} else {
VStack {
Spacer()
Image("share sheet")
.resizable()
.frame(width: 300, height: 200)
.matchedGeometryEffect(id: "img", in: namespace) …Run Code Online (Sandbox Code Playgroud) 我正在探索 Xcode 12 和 SwiftUI 2.0 中的新事物
我在 Xcode 12、iOS 14、Swift UI 2 中创建了一个带有 TabView 和 PageTabViewStyle 的页面浏览载入屏幕。我想在点击它时添加下一个按钮,页面应该移动到第二个视图。这里Text("Hello")。
struct OnBoardingView: View {
var body: some View {
TabView {
Text("Hi")
Text("Hello")
Text("Welcome")
}
.tabViewStyle(PageTabViewStyle())
.indexViewStyle(PageIndexViewStyle(backgroundDisplayMode: .always))
}
}
Run Code Online (Sandbox Code Playgroud) 我有三观。我想隐藏第三个视图中的导航栏。即使我给.navigationBarHidden(true)导航栏显示!
我找不到我做错的地方。我附上了我的代码和下面的截图。
Xcode 版本 - 11.1
struct ContentViewOne: View {
var body: some View {
NavigationView {
ZStack {
Color.yellow.edgesIgnoringSafeArea(.all)
VStack(spacing: 20) {
Text("View One")
NavigationLink(destination: ContentViewTwo()) {
Text("Navigate to View Two")
.foregroundColor(.white)
.padding()
.background(Color.red)
}
}
}
.navigationBarTitle("View One")
}
}
}
struct ContentViewTwo: View {
var body: some View {
ZStack {
Color.green.edgesIgnoringSafeArea(.all)
VStack(spacing: 20) {
Text("View Two")
NavigationLink(destination: ContentViewThree()) {
Text("Navigate to View Three")
.foregroundColor(.white)
.padding()
.background(Color.red)
}
}
}
.navigationBarTitle("View Two")
}
}
struct …Run Code Online (Sandbox Code Playgroud) 我有一个按钮,当我点击它时,一个新的视图将显示为一个工作表。在 SwiftUI 中,默认情况下向下滑动手势将关闭工作表视图。我想限制它。
我会有一个解雇按钮。在我按下那个按钮表之前,不应被解雇。
我正在做一个登录屏幕。单击登录按钮后,我将对响应进行 API 调用,并将用户重定向到主屏幕。
问 - 如何通过单击按钮并执行某些操作从一个视图导航到另一个视图。
我已经试过了,以 编程方式导航到 SwiftUI 中的新视图
但我收到了一个错误,比如
“函数声明了一个不透明的返回类型,但它的主体中没有返回语句来推断底层类型”
请帮我解决它。
我可以通过以下实现访问didFinishLaunchingWithOptions。但是,我需要UIWindow变量。我不知道如何得到它。我正在使用 Xcode 12 测试版。iOS14,SwiftUI 生命周期。
import SwiftUI
@main
struct SSOKit_DemoApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
print("hello world!!!")
return true
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个表格来显示我的应用程序中的操作列表。我可以删除该表中的任何操作。因此,我在每一行中添加了一个删除按钮。此删除按钮将触发“删除确认”引导模式。
<table class="table table-hover">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col" class="th-lg">Name</th>
</tr>
</thead>
{% for action in actions_list %}
<tbody>
<tr class="test">
<th scope="row" class="align-middle">{{ forloop.counter }}</th>
<td class="align-middle">
{{action.action_name}}
</td>
<td class="align-middle">
{{action.id}}
</td>
<td>
<div class="row justify-content-end">
<button
id="edit"
type="button"
class="btn btn-sm btn-dark col col-lg-2"
style="color: rgb(255,0,0,0)"
>
<i class="lni-pencil"></i>
</button>
<button
id="trash"
type="button"
class="btn btn-sm btn-dark col col-lg-2"
style="color: rgb(255,0,0,0)"
data-toggle="modal"
data-target="#modalConfirmDelete"
>
<i class="lni-trash"></i>
</button>
</div>
</td>
</tr>
</tbody>
{% endfor %}
</table>
Run Code Online (Sandbox Code Playgroud)
以下是“删除确认”引导模式的代码。它将有“是”和“否”按钮。如果我单击“是”,则该特定操作 ID 将被传递到 …
我正在做一个由 5 个带有单选按钮的选项组成的页面。当我们点击一个选项时,元素的颜色应该改变。我从 API 响应中获取这些选项。我正在使用 MVVM 模型。我附上下面的代码。
我所困扰的是,当我改变布尔值时,它没有改变!
查看型号代码
import Foundation
import Combine
class DCListViewModel: ObservableObject {
@Published var DCList = [DCViewModel]()
init() {
fetchDcs()
}
func fetchDcs() {
ARMServices().getAllDc { (dcArr) in
if let dcArr = dcArr {
for dc in dcArr{
self.DCList.append(DCViewModel(dc: dc, isSelected: false))
}
}
}
}
}
class DCViewModel {
var id = UUID()
var dcStruct: DC
var isSelected: Bool
init(dc: DC, isSelected: Bool) {
self.dcStruct = dc
self.isSelected = isSelected
}
var url: String …Run Code Online (Sandbox Code Playgroud)