Pure Swiftui Login, Signup, Register Flow, Is It Possible

Combining different views in one app

If You start with a window-based application, You can first set your login viewController as rootViewController of the main window and then, after the user has logged in, set the tabBarController as rootViewController.

Also take a look at this old question: How to develop a TabBar based application with a login functionality?

NavigationTitle visual glitches - transparent and not changing state from .large to .inline on scroll

For this to work flawlessly the ScrollView needs to be the direct child of the NavigationView. I ran into a similar issue with wanting to dismiss the TabView when I navigating but SwiftUI won't let that happen. Each tab needs to be a NavigationView and you need to dismiss the TabView creatively if that is what you want.

TabView {
NavigationView {
ScrollView {
// your view here
}
}.tabItem {
// tab label
}

// etc
}

Essentially the navigation view needs to be a child (in the brackets) of the tab view and the scrollview needs to be the direct child of the navigation view.

User input to change size of shape that is generated by tap

To increase / decrease sphere's radius and then position sphere by tap, use the following code.

Now, with working button and coordinator, it will be much easier to implement a raycasting.

import SwiftUI
import RealityKit

struct ContentView : View {
var body: some View {
PrevView().ignoresSafeArea()
}
}

Reality view.

struct Reality: UIViewRepresentable {

@Binding var input: Float
let arView = ARView(frame: .zero)

class ARCoordinator: NSObject {
var manager: Reality

init(_ manager: Reality) {
self.manager = manager
super.init()

let recognizer = UITapGestureRecognizer(target: self,
action: #selector(tapped))
manager.arView.addGestureRecognizer(recognizer)
}

@objc func tapped(_ recognizer: UITapGestureRecognizer) {

if manager.arView.scene.anchors.isEmpty {
let model = ModelEntity(mesh: .generateSphere(radius:
manager.input))
let anchor = AnchorEntity(world: [0, 0,-2])
// later use AnchorEntity(world: result.worldTransform)
anchor.addChild(model)
manager.arView.scene.anchors.append(anchor)
}
}
}
func makeCoordinator() -> ARCoordinator { ARCoordinator(self) }
func makeUIView(context: Context) -> ARView { return arView }
func updateUIView(_ uiView: ARView, context: Context) { }
}

PrevView view.

struct PrevView: View {

@State private var input: Float = 0.0

var body: some View {
NavigationView {
ZStack {
Color.black
VStack {
Text("\(String(format: "%.1f", input)) meters")
.foregroundColor(.yellow)
HStack {
Spacer()
Button(action: { $input.wrappedValue -= Float(0.1) }) {
Text("Decrease").foregroundColor(.red)
}
Spacer()
Button(action: { $input.wrappedValue += Float(0.1) }) {
Text("Increase").foregroundColor(.red)
}
Spacer()
}
NavigationLink(destination: Reality(input: $input)
.ignoresSafeArea()) {
Text("View in AR")
}
}
}.ignoresSafeArea()
}
}
}


Related Topics



Leave a reply



Submit