how to make swiftUI buttons exclusive? - swiftui

using swiftUI i have a lot of Buttons which i need to make only one can be clicked at the same time.
By default in swiftUI you have two or more buttons on a view you can click them all at once
I tried adding the following:
UIButton.appearance().isMultipleTouchEnabled = false
UIButton.appearance().isExclusiveTouch = true
With UIKit we had exclusiveTouch and MultiTouchEnabled but how do we do this with swiftUI?
What is the correct way to solve this application wide?
Update: The use case is simple there is a view with a login button and a register button and now the user can tap both at the same time which i don't want

Related

Android navigation component- With Login screens

When dealing with login screens, I am trying to work out the better approach - either execute navigation "action" to go to login fragment on first use (and hide back button to actual app), or start a new login activity (with its own nav graph). For the first approach (just using navigation components), I do not know the way to remove the back button without a hack "hide". I tried using navoptions, setpopupto etc., but it does not work. Code below:
val navOptions = NavOptions.Builder()
.setPopUpTo(R.id.home_fragment, true)
.build()
host?.navController?.navigate(R.id.action_global_signUpFragment_dest, null, navOptions)
Two questions then:
1) How to properly handle login transition with just navigation component?
2) Is starting a new login activity, with separate nav graph, a better idea?
I think the first approach is better.
To hide the 'back' button on your toolbar inside signUpFragment you can use AppBarConfiguration, and customize which destinations are considered top-level destinations.
For example:
val appBarConfiguration = AppBarConfiguration.Builder(setOf(R.id.home_fragment, R.id.signUpFragment_dest)).build()
NavigationUI.setupWithNavController(toolbar, navController, appBarConfiguration)
This way home_fragment and signUpFragment_dest will be considered top-level destinations, and won't have back button on toolbar.
Another option for solving the back button problem is how I did it here. Also, rather than show/hide the bottom nav bar, I have two NavHostFragment, one main full screen one, and one contained within the home fragment (above the bottom nav bar).
When I want to navigate to a full screen view I call this extension function,
fun Fragment.findMainNavController(): NavController =
Navigation.findNavController(activity!!, R.id.nav_host_fragment)
then navigate via the main graph.
This makes sense conceptually to me, to have parent and child nav graphs.

UIButton not getting focus

I have my code in Swift 3. I have two UITextFields and a UIButton in my view. I have the textFieldShouldEndEditing delegate of the first UITextField which is fired when I focus on the 2nd UITextField. However when I tap on the UIButton this delegate is not fired. I had thought that when a UIButton gets focus then the UITextField’s event will automatically fire since it is losing focus. However, when I tap on the UIButton, the cursor is still blinking in the UITextField, which means it is not losing focus.
Any ideas on why the UIButton is not getting focus will be most appreciated.
Thanks.
This is an infuriating aspect of developing forms on iOS. Button taps don't remove focus from UITextField / UITextView the same way they would in an HTML form.
I'm sure there are more elegant ways to solve this, but if I want to consistently do this across all forms I ensure that the following line of code is run when users tap on any buttons of mine.
- (void)userDidTapButton:(id)sender
{
[[[UITextField new] becomeFirstResponder] resignFirstResponder]
// the above embarrassing line of code basically creates a new textfield
// puts focus in it (thereby removing focus from any existing textfields
// and then removes focus again
// this ensures that delegate events fire on your existing textfields
// finally, run any other button code
}

Swift 3 disable Control-Center and statusbar swipe

I will build an app. The User can leave the App only by click in the end Button or with the Homebutton.
Now of i swipe down the statusbar is shown. Same with swipe Up from the Button the Control Center comes Up.
Can i disable this? In xcode i checked hide statusbar and requires fullscreen.
The statusbar is hidden.
I removed the gestureRecognizers:
In viewDidLoad:
Self.view.gestureRecognizers?.forEach(View.removeGestureRecognizer)
Or cant i disable the swipe Up/swipe down for controlCenter,notificationscreen
Thanks
Sadly you can't, it's just to allow the users to keep those features accessible and not having the app to block their phone.

Repositioning Master View display button in Split View Controller

As you know, split view controller hides the master view and displays detail view in full screen mode in ipad. In the full screen mode, ios creates a bar button for the master view on the navigation bar. My question is, is it possible to reposition that button to the far right instead of left? Because my detail view is embedded inside a navigation view controller and there are severals views associated with it. It gets confusing when master view is hidden and the detail view has button to go back to the previous view.
In above screencap, "Category" is a button to display the masterview and "List of Events" is a back button. If you have better way to handle this situation, please feel free to suggest.
Yes, you can do it just send a NotificationCenter.default to the split view controller and change self.preferredDisplayMode in your splitview and coming to moving the category buttom u either can use the right bar button in navigationbar or create your custom navigation bar.
Hope this helps
For those who are having the same issue, I found a very simple solution. All you need to do is assign the rightBarButtonItems with leftBarButtonItems value and set the leftBarButtonItems to nil. Voila, that's about it.
if let leftButton = self.navigationItem.leftBarButtonItems {
self.navigationItem.rightBarButtonItems = leftButton
self.navigationItem.leftBarButtonItems = nil
}

Using Storyboards Get TabBar Reference for UIActionSheet showFromTabBar

I have a storyboard with an initial splash view controller followed by a tabbar controller, navigation controllers, and tableview controllers. I need to present an action sheet from one of my tableview controllers.
[UIActionSheet showInView:self.view] does not work, because touches that fall in the tab bar area are not detected, so I must use [UIActionSheet showInTabBar:tabBar].
My question is how can I get a reference to the tab bar or the UITabBarController. Xcode does not allow me to connect a referencing outlet from the UITabBarController or from the UITabBar to any of my custom view controllers (presumably because view controllers on a storyboard are not static objects, but are only created when necessary and related by segues (?), so you aren't supposed to do it that way), but this leaves me with no way to get at the tab bar directly.
What is the right way to do this ?
There is probably a better answer to this question over here:
Storyboard - UITabBarController
In short, pull the root view controller off your appdelegate's window.
I just did the following in my viewWillAppear to hide my tab bar for that particular view:
AppDelegate *ap = (AppDelegate *)[[UIApplication sharedApplication] delegate];
UITabBarController *tc = (UITabBarController *)[[ad window] rootViewController];
[[tc tabBar] setHidden:YES];