Search results for

swiftui

16,633 results found

Post

Replies

Boosts

Views

Activity

SwiftUI and ARKit BodyTracking
Is anyone else seeing issues with ARkit Body Tracking and SwiftUI?I am finding the the face tracking works fine if you have a view that appears with ARKit, does the tracking then goes away. This can consistently be done over and over by switching to the view and using it.But I can't do the same with BodyTracking. If I have a view that is making use of BodyTracking then it only works if I show ONLY the view with the body tracking as the very first thing to appear when running the app. If I show any other views before switching to the one with the BodyTracking then it does not work. Also if I display that first view (which works fine) the switch to another view and back to the BodyTracking view then it no longer works.This feels like a bug in ARKit, SwiftUI or iPadOS (don't have a phone to try it out).Anyone else running into problems with SwiftUI and BodyTracking?I get the following output when running my App (both when it works and when it doesn't). Feels to me like SwiftUI
3
0
2k
Sep ’19
Reply to SwiftUI and ARKit BodyTracking
Specifically the problem I am seeing is that the ARBodyAnchor is never found during the second attempt when using the View again.Note that I am creating the ARView inside its own UIViewController itself, which is then wrapped in a UIViewControllerRepresentable for use in SwiftUI. func session(_ session: ARSession, didUpdate anchors: [ARAnchor]) { for anchor in anchors { guard let bodyAnchor = anchor as? ARBodyAnchor else { continue } //Never gets here after displaying the view the second time around.Mainly what I am after here is acknowledgement from anyone else so that I know it's not just me. Then if possible advice for a workaround to get it going in SwiftUI. But my current plan is now to throw away my app completely and start again using the traditional app development approach (ie No SwiftUI at all, use storyboards and UIViewControllers the whole way). Which is what the example BodyTracking code does anyway, which makes me even more suspicious that it doesn't work properly yet
Topic: Spatial Computing SubTopic: ARKit Tags:
Sep ’19
Use of undeclared type 'UIViewRepresentable' in macOS project
Hi,create macOS project and I try to make UIViewRepresentable but get this error.import SwiftUI struct WebView: UIViewRepresentable { //Error: Use of undeclared type 'UIViewRepresentable' }What can I do with it or how can I make my own UIViewRepresentable for macOS to use WKWebView in my project?struct WebView: UIViewRepresentable { func makeUIView(context: Context) -> WKWebView { WKWebView() } func updateUIView(_ uiView: WKWebView, context: Context) { } }My question on stackoverflow
2
0
8.3k
Sep ’19
Preview fails in SwiftUI tutorial
I am attempting to go through the SwiftUI tutorials on the Apple developer website - building the Landmarks app. With each starting point they provide a project file. When I open the project in XCode, everything works fine. However, when I add a new SwiftUI View to the project the preview (canvas) fails to load the default Hello World view. It states Failed to build Test.swift. Restarting XCode and/or rebooting the machine does not resolve the issue.When I add a SwiftUI View to a project that I originally created on my Mac, the preview works fine. Is there an issue with the starting point project files provided in the tutorials?This issue is preventing me from being able to do the tutorials, so any advice would be greatly appreciated!
1
0
1.5k
Sep ’19
How do you create a one to many relationship with Core Data Model for CloudKit?
I can't seem to figure out how to get a one-to-many relationship working with a NSPersistentCloudKitContainer. Has anyone been able to do this successfully? I see the relationship that is one-to-one on the other end, but not the relationship which is supposed to be many to many.I've been trying to use the information here https://developer.apple.com/documentation/coredata/mirroring_a_core_data_store_with_cloudkit/creating_a_core_data_model_for_cloudkit#3191035and am unsure if this is a limitation of CloudKit and CoreData, if the data is there and just not showing in the dashboard or any other option.I've put my code here on Github https://github.com/jknlsn/testcloudkit and would love any help or thoughts. I would also be very keen to hear of any better ways to be debugging and visualising this data I am trying to write apart from the CloudKit dashboard, I don't know yet how to retrieve and display the data with SwiftUI.
1
0
1.2k
Oct ’19
Tappable area expands with clipped Image
Hello!I'm having a hard time finding a workaround for this SwiftUI bug. At least I think it is a bug as I cannot find anything related to it anywhere.So I have the following code in a View:ForEach((1...5), id: .self) { index in HStack(spacing: 24) { Image(tallImage1200x1800) .resizable() .aspectRatio(contentMode: .fill) .frame(width: 150, height: 120) .clipped() Text(Random text) } .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .leading) .background(Color.white) .clipShape(RoundedRectangle(cornerRadius: 15)) .shadow(color: Color.black.opacity(Double(0.3)), radius: 1, x: 1, y: 1) .padding(.vertical, 6) .padding(.horizontal, 16) .frame(height: 120) .onTapGesture { print((index)) } }The problem is that if you now tap on the lower part of any of the HStacks you will actually get the index of the next card printed out. This clearly happens because the tappable area is expanded to the new top and bottom bounds of the resized image.As a workaround I tried:- adding an
3
0
4.8k
Oct ’19
.sheet with tabs in SwiftUI
Hi, I'm trying to build an app with a card-based interface, where each step down the navigation hierarchy presents a new card on top of the old one. I've built something manually that works *OK*, but the way that calling a sheet works is so much smoother and feels much more native.The problem is that my app uses a Tab View, which should still be usable when these cards start tsacking up. Does anyone know a way to bring up a sheet, without obscurring the tabs, or know another technique that might work?Thanks,T.
0
0
354
Oct ’19
UITabBar "barTintColor" Does Not Change Back to Light Mode Color in SwiftUI
I created an app with a TabBar and utilized AppDelegate to control it's background color using the code below. I have a custom ColorSet in Assets (headerFooter) that sets the Light and Dark mode colors for my TabBar. The app will not change the TabBar back to the correct Light Mode color when I change from Dark to Light in the simulator or on my iPhone X.I am using Catalina v10.15 beta (19A578c) and Xcode 11.2 beta. My iPhone is running iOS 13.1.2.With the phone in Dark Mode, I open the app and it opens with the correct colors. Conversely, when I start the app with the phone in Light Mode, the app opens with the correct colors. When I change from Light Mode to Dark Mode, the colors change accordingly. However whenever I change from Dark Mode to Light Mode, the TabBar remains showing the Dark Mode color.UITabBar.appearance().barTintColor = UIColor(name: headerFooter)Any ideas?Thanks,Doug
3
0
4k
Oct ’19
Reply to iOS 13: UIScrollView no longer scrolls
You should detail the exact setup.Unfortunately, no image possible on the forum.Is it Swift or SwiftUI ?have you defined constraints on different views ?How is the scrollView defined (whole size, content offset …)I tested some mockup code and seems to work (iOS 13 simulator).I set the scrollView background to color to see it.class ViewController: UIViewController { @IBOutlet weak var scrollView: UIScrollView! @IBOutlet weak var segmentedControl: UISegmentedControl! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. scrollView.contentSize = CGSize(width: 1000, height: 1000) scrollView.contentOffset = CGPoint(x: 50, y: 50 ) } @IBAction func selectSegment(_ sender: UISegmentedControl) { print(segmentedControl.selectedSegmentIndex) } }Then I can scroll the view and make next segments to appear.I can select segments from 0 to 7.Is is important that the scrollView contentSize be larger than the frame, otherwise, no scroll.
Topic: UI Frameworks SubTopic: UIKit Tags:
Oct ’19
Reply to UITabBar "barTintColor" Does Not Change Back to Light Mode Color in SwiftUI
Where in the AppDelegate are you using this code? Also, if this is a SwiftUI app, you'll have better luck setting the colors on TabView itself using a modifer.SwiftUI will automatically re-render your views when you switch to and from dark mode. I imagine the issue here is the AppDelegate method that you're using isn't being called again after you change to (and from) dark mode.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’19
How to pop SwiftUI NavigationLink view on changed condition (received from delegate)?
I have a SwiftUI view that is pushed on the navigation stack (using a NavigationLink).This view is a UIViewRepresentable-wrapped UIKit-based view.To receive delegate events from my UIKit-based view, there is a Coordinater class (which is instantiated in makeCoordinator()).I now want to dismiss my SwiftUI view when one of the delegate method calls indicates a certain condition.The only way I know to dismiss a NavigationLink-pushed-view is via: @Environment(.presentationMode) var presentationMode: Binding<PresentationMode>But when I invoke in the my implementation of a delegate method (i.e., inside my Coordinator): self.mySwiftUI.presentationMode.wrappedValue.dismiss()this result in a crash: Thread 1: Fatal error: Reading Environment<Binding<PresentationMode>> outside View.body.Knowing that SwiftUI is a declarative way of creating UIs, how do I ever get this dismiss() function called? Is there a way to call a function when a @State variable changes for example?
1
0
4.1k
Oct ’19
Reply to How can I change my NavigationView's accent color depending on its current content?
I figured out the correct answer, and it is all to do with PreferenceKeys. Given that the accent color lives in the environment (according to the WWDC talks, anyway) it seems a rather roundabout way of changing this, but needs must and all that.It ultimately took four pieces:A @State variable in the root view (containing the NavigationView) whose value would be passed to the .accentColor() modifier on the navigation view.A PreferenceKey type with a value matching the parameter for .accentColor() (e.g. a Color?).An onPreferenceChange() modifier on the navigation view that resets the state variable to the preference value.A .preference(key:value:) modifier on the pushed view setting the new color.With this, when the detail view is pushed it will set the preference, the top-level view will react by updating its state, and SwiftUI will respond to that by re-fetching the top level view, which will get the new accent color. When you pop the detail view, the preference value will be reset to the value used
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’19
Crash with List using Observable Object
Hello,I'm using swiftUI to render my interface, the goal is to made a simple tableView. I'm using List, passing a param that is an array from an observableObject. The array isn't empty and each element is one identifiable that has an UUID. But, my application crashes when I try to show the list on the screen. The error:[TableView] Warning once only: UITableView was told to layout its visible cells and other contents without being in the view hierarchy (the table view or one of its superviews has not been added to a window). This may cause bugs by forcing views inside the table view to load and perform layout without accurate information (e.g. table view bounds, trait collection, layout margins, safe area insets, etc), and will also cause unnecessary performance overhead due to extra layout passes. Make a symbolic breakpoint at UITableViewAlertForLayoutOutsideViewHierarchy to catch this in the debugger and see what caused this to occur, so you can avoid this action altogether if possible, or defer it
4
0
5.6k
Oct ’19