SwiftUI restrict drag gesture that changes view in TabView - swift

I have code that enables me to change views programatically using buttons by making use of
TabView(selection: $VM.selectedPage) {
ViewOne()
.tag(0)
...
}
And I am able to restrict users from progressing to the next view until user input is given, however they are still able to swipe through the views and bypass my restrictions.
I want to either add the same restrictions to the swipes as I have done with the buttons, or prevent the use of swiping to switch between views altogether.

Related

In watchOS, is it possible to display a view without a status bar button that leads to the root view?

I would like to have a similar navigation structure to the built-in Workout app in watchOS. I have a list of tennis rules formats, analogous to workout types in the Workout app. Tapping one starts a match in a new interface controller. In WatchKit, as far as I know, I can only push an interface controller or present one. Both approaches risk the user canceling the match earlier from the top left chevron or tapping the status bar in a presented modally.
The workout does not have that limitation during a workout session, instead, the user ends the workout from switching pages in its page-based navigation. Does SwiftUI with its fully programmatic way of watchOS app development allow for accomplishing this?
Below is the initial view of the Workout app
Selecting a workout switches to a screen where the top left title isn't tappable, which is what I'd like to accomplish (the initial view is completely hidden and does not show when you swipe between the three pages)
Maybe you need to modify your view with:
.navigationBarBackButtonHidden(true)
Did you try that?
I think you need to take a look at reloadRootPageControllers()
See https://developer.apple.com/documentation/watchkit/wkinterfacecontroller/2868441-reloadrootpagecontrollers
The basic idea appears to be that you are replacing the current interface controllers with the named ones listed in this method.
WKInterfaceController.reloadRootPageControllers(withNames: ["workout","nowPlaying"], contexts: [workoutToRecord], orientation: WKPageOrientation.horizontal, pageIndex: 0)
In my Interval Training app I call this method once a user has selected their workout. and this interface is then replaced with workout interface and now playing page.
You will note that there is no back button for them to accidentally return to the workout select screen.
Hope that helps.

Navigating view using swipe

I am making a weather app with left, right gesture controls. Meaning a user could have multiple cities whose weather they want to check by swiping left/right on the screen. See screenshots of a sample app that I would like to mimic behavior of.
I have two questions.
How in the world are they showing the transition between two views in the second screenshot? I tried to replicate the same behavior in Xcode - storyboard. I created two view controllers, one with red background and other with green. I dragged and dropped swipe gesture recognizers on the red one and related the gesture to view controller to the other one using Modal. But only default transitions I see are flip horizontal/vertical, cross dissolve, partial curl. Nothing like what they have going on. So how are they doing that? Changing to Push doesn't do anything.
If I use storyboard then I am limiting the cities user can enter. Meaning if I have two view controllers then view controller 1 will show weather for city 1, view controller 2 will show weather for city 2. Basically swipes are limited to how many controllers I have defined. (one for each city). Is there a way I can make this dynamic? Users can have N-number of cities and N-number of swipes. Similar behavior to weather app that comes built in with every iPhone.
If you are letting the user enter their own cities, you should only create one UIViewControllerthat handles a single city. Then you just need to create a UIScrollView with paging enabled (here's a tutorial) and then hide the page scroll indicator like Solar does. Create several instances of you UIViewController and add their views to your UIScrollView.
Solar fades in the view of the controller that is becoming visible while fading out the one that is being hidden. This is done using the UIScrollViewDelegate methods, that allow you to know when the scroll view is being dragged.

iPhone Swipe UIKeyboard to Switch Views

I want to achieve something like this with my application and its keyboard.
http://www.youtube.com/watch?v=ajs1p5NCNw4 from 1:32 - 1:38.
How can you hide your keyboard by swiping it horizontally and show another view on its place? Is it possible with default keyboard or should I create my own view with few buttons which I'll need and then add the swiping? (I know how to do this, but I'm not sure if apple wouldn't deny the app in app store because I implement my own keyboard or something like that)
Those are custom views. It might be a scroll view with paging enabled and two subviews (the numerical keypad is one subview and items view is the other subview).
The app might be using the custom view in place of the system keyboard, by setting the inputView property of a text field for example. Or it might just be displaying the custom view as a subview of its top-level view.

Mimicking iOS notification view

I am trying to mimic iOS 5's notification view (when you swipe down the view appears) for hub with a left swipe in my view. I created a mimic for a single view controller by adding the hubview as subview and changing the origin of view when making swipe. But With this approach I have to add it to every view I implement in my app. I want to add it to UIViewController as a category. I am not sure how to proceed at this point.
If you don't want every viewController to have to handle the menu then I would suggest having a root viewController that acts like a container. It has a subview that displays the content from your various view controllers and it also has the controls for your menu and any other overlay information you may want to provide.
A category won't work in this case but subclassing will. Just ensure that all of your view controllers are sub classes of the view controller with this functionality implemented.

Multiple View Controllers being loaded at the same time. iPhone app

I am trying to create an app that swipes over through multiple view controllers on a UIScrollView - similar to how one would see different windows in the safari app, but instead of tapping a button to move between them, I am swiping the scroll view.
Now, I will be getting notifications when any of the data in a particular view is to be updated with some json. Should I be updating the view that aren't showing (but are on the scroll view), or should I wait until the user scrolls to that view?
I am very concerned about performance here. Hopefully I am being clear in the question.
Thanks!
You should update the views next to the view that you are viewing I would say. And when you switch (scroll) to another view, then update the views next to that view. (Assuming you have received new JSON data)