SwiftUI: disappearing popover on iPad only on some Views - swift

I am experiencing problem with .popover() in SwiftUI it sometimes works correct, and other times it just appear and immediately disappear. Logging value of isPresented binding variable seems to show correct value.
Any idea why such thing can happen?
Moreover I have the same AddAttachment button that has popover() call added to different screen views and in one it works ok in other it stops working. Adding logs to init() of this screen views shows that value of isPresented #Binding var is ok (it is called several times (init()) but there is isPresented == true all the time after tapping button that should show popover). If popover disappear then taping button again changes #Binding var to false (so nothing show), and second consecutive tap make popover to appear and again immediately to disappear.

Related

SwiftUI add view to NavigationView

I'm currently working on rewriting a VoIP app from UIKit to SwiftUI. In the UIKit version, we have an active call screen with a button that when tapped, closes the active call screen and lets you interact with the app. Tapping this button also adds a view to the UINavigationController, basically covers most of the navigation view and when tapped, returns the user back to the active call screen.
I'm experimenting with different ideas in SwiftUI, but haven't hit on any solid ideas yet and wanted to see if the community had any ideas for accomplishing this.
Here's a sample of what the UIKit code:
class MainNavController: UINavigationController {
func showActiveCallBar() {
...
let activeCallBarView = ...
...
view.addSubview(activeCallBarView)
}
}
Here's a gif of what happens when we switch back and forth, sorry, couldn't show the whole app. You can see the whole upper portion of the Navigation View gets covered.
Thank you!
In SwiftUI, we would accomplish something like this with an #State variable, which would track wether we want to show the active call bar.
When your state variable changes, your SwiftUI view will be updated and the active call bar will be shown or hidden. It might look something like this.
struct PlayButton: View {
#State private var showActiveCallBar: Bool = false
var body: some View {
if (showActiveCallBar) {
ActiveCallBarView()
}
// ... Other Views
}
}
The SwiftUI documentation of State has more helpful information, and the SwiftUI docs generally are quite helpful in this regard. You could start with the SwiftUI tutorials https://developer.apple.com/tutorials/swiftui

How to detect a click from an NSToolbarItem inside an NSWindowController?

I have a toolbar on my macOS app, developed in Swift. The toolbarItem is dragable onto the NSWindowController, and I can setup an IABAction function, I just have a print in the function at the moment. And when I click on the button nothing happen the click does not seem to be recognised as an action ?
I had a few more line of code in the function but deleted it and now have just the print("test") line.
#IBAction func exportCsvClicked(_ sender: NSToolbarItem) {
print("test") }
No output observed, so I'd love to get "test" in the console when I click on this button.
Here is a list of the connections associated with the toolbarItem.
I found a way to get around the fact that the IBAction from an NSToolbarItem does not recognise the click on this item:
1/I made a customSegue from the item to the main window controller (it can go anywhere)
2/The prepare for segue function posts a notification to the notification saying that the item has been clicked.
3/The main view controller observes the notification and presents, either has a popup or a sheet (I got two buttons), the view that I have setup in the storyboard (referencing with the storyboardID). I found that you need to pass on all the necessary variable to setup the view from the main view Controller, and that there was issue of code in the viewDidLoad function of the sheet/popup view not running, I am suspecting that they might be different instances.

Buttons of one particular view controller are not working

On tapping one button of first view controller, I am navigating to second view controller with performSegueWithIdentifier(identifier is given in storyboard and working fine).Second view controller will be shown in Landscape mode.
In second view controller there is a mapView(google). below the map, there is one button; on top of the map there is one more button, but both the button actions are not working.
userInteractionEnabled, enabled , accessibility all are correct.
Action methods are also dragged from storyboards properly and have been properly connected.(Removed and even connected again also)
Still action methods are not getting called. Buttons are also not clickable there.
Couldn't find the reason. thanks for help.

Button not always getting the touch. Touch sometimes goes to another View Controller

I'm looking for some kind of solution to a problem I have.
I have a main view controller. On this view controller I have a button it works well most of the time. But when i pop up smaller view controller onto my main view controller, a part of the small view controller is behind the button.
So the button is is still on the front of the sceen, with the small view controller behind it.
The small view controller seems to take the key presses that were ment for the button. Is there a way to get the button to take the keypresses? I though it having the higher z order would make this so, but obviously not. Is there a work around of this?
Or am I going to need to have an invisible button on my small view controller that calls back to the parent view controller to say the button was pressed.
Many Thanks
C :)
Key presses go to the first responder of a window not the frontmost view in the z order. So after popping up the small view controller make the button first responder then key presses will go to it.

iPhone: Is there a way of keeping track of touches while changing views with UINavigationController?

I'm currently working with 2 views on a UINavigationController.
I have a Leaves view (Tom Brow's leaves project) to simulate curling effect for pages which only works with images, and my actual view controller with the page and it's contents.
What I'm trying to do is, when tapped on certain place, popViewControllerAnimated:NO the actual view controller, leaving the leaves view behind on top and trying to do the page turn without having to tap again on the screen and keeping things as if no switch ever happened.
My issue here is that the touches seem to go through a black hole and never get to the current view. I've even tried to catch the touches with a custom UIApplication subclass, but as soon as the first view gets popped the touches start coming with nil view and window and phase = UITouchPhaseStationary.
The views in the navigation controller are pushed: one as the rootViewController in the init method and the other with a pushViewController:animated:.
Is there something I'm missing or there's just no way to keep touches through views in a UINavigationController?
EDITED: Final solution, clear overlay to get touches