does anyone knows how to disable the swipe forward and backward feature in ios.
I am using angularjs and stuck in a problem where user can swipe back and forward this disturbs my functionality of the app. any lead would be appreciated.
I don't think you can accomplish exactly what you are trying to do. I have run into this issue as well - where I need to save some piece of data before the user goes back to a previous view controller. Reacting to a button tap is easy with an IBOutlet and some simple logic. But when the user has the ability to swipe to go back with functionality built into UINavigationControllers, it's not so cut and dry now.
Instead of trying to swim against the current, why not use this new ability?
Using viewWillDisappear, check if the current view controller is no longer in self.navigationController's stack. If it isn't than we are Oscar Mike to a different view controller and you should save your data.
-(void) viewWillDisappear:(BOOL)animated {
if ([self.navigationController.viewControllers indexOfObject:self]==NSNotFound) {
[self saveImportantData];
}
[super viewWillDisappear:animated];
}
While I'm sure this isn't what you asked for, maybe it is a workaround that will help you.
if u have the access to viewcontroller file,then u can use the above code to disable the screen panning
- (void)viewDidLoad {
[super viewDidLoad];
if ([self.navigationController respondsToSelector:#selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}
}
Related
I don't have a ton of experience with iOS development, but I feel like this should be possible. What I'm trying to do is do an IBAction within a second view controller. The IBAction is I'm trying to preform looks like this:
- (IBAction)helloWorldButton:(id)sender {
[self.textDocumentProxy insertText:#"Hello World"];
}
I've linked up the send event to touch up inside. I am able to pull up the second view controller and properly dismiss it with:
- (IBAction)dismissSecondView:(id)sender {
[[self presentingViewController] dismissViewControllerAnimated:NO completion:nil];
}
That all works fine which is what's confusing me. Why does the IBAction for dismissing the view controller work but the IBAction for textDocumentProxy doesn't? I can provide more code and information if needed, but I have successfully linked up the two view controllers to appear and be dismissed. I just want a button that types "Hello World" within the secondary view controller.
Thank you for your help in advance!
I figured it out. I was thinking about it all wrong. What I was looking to do was change the label on multiple buttons, not change the entire view. What I did was this:
Take the button to change the state of other buttons, and tell it tell it to change the buttons accordingly using
- (IBAction)buttonChanger:(id)sender {
if ([_aButton.titleLabel.text isEqual: #"Hello"]) {
[UIView setAnimationsEnabled:NO];
[_anotherButton setTitle:#"World" forState:UIControlStateNormal];
[_lastButton setTitle:#"Friend!" forState:UIControlStateNormal]; //more buttons after this...
Not sure if that example makes a ton of sense (changed the variables up a bit from the original project) but that will change each button accordingly. When I push button "Button Changer", it checks the status of "aButton" to see if anything needs changing, and then changes the title of the other buttons (anotherButton, lastButton) to World and Friend! accordingly. This is exactly what I was looking to do. I realize this is a completely different route to what I was initially thinking, but it works great!
Thanks for your help!
I'm using an open source messaging UI library for an app that I'm building. When users start a new conversation I want the "chat view" to appear with the keyboard already up and the cursor on the textfield (similar to most existing chat applications). Is there a way to force the JSQMessagesViewController to appear with the keyboard already up?
I tried implementing this using:
self.keyboardController.textView.becomeFirstResponder()
However, this caused the keyboard to pop up immediately when the view was presented... yet the toolbar would lag behind by about a second (not too much, but painfully noticeable). In addition, this solution seems to disable the keyboard from being dismissed using a downward gesture as it normally does.
Is there something I'm missing that solves this out of box? Or will I have to modify the library to get this bit of functionality... and if so, where do I begin doing that?
try to do like this
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
[myTextField becomeFirstResponder];
}
--> It will make focus on myTextField and open the keyboard automatically. Hope it may help you.
This worked for me. It's in swift, but should be easy to translate.
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(false)
self.inputToolbar!.contentView!.textView!.becomeFirstResponder()
}
I wanted this with a button click so I added:
[self.inputToolbar.contentView.textView becomeFirstResponder];
If you want yours when it loads add:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self.inputToolbar.contentView.textView becomeFirstResponder];
}
This maybe too late, but in my case I forgot to call super.viewDidAppear(animated) which caused text view to lag behind keyboard. Once I added that call, problem went away.
I am stuck in googlemap integration. I am working with google map actually i want to kill a map view on button click as it is consuming too much memory how it can be kill? i just want to unload a map in my app. below is my sample code but it is not working..
(IBAction)menuButtonPressed:(id)sender {
[super menuButtonPressed:sender];
self.mapView_=nil;
}
but not working kindly help me regarding this..
All that you code does is remove the local reference to the map view. As the map is still visible in your view, it won't be released as the view will be holding a strong reference.
Try
- (IBAction)menuButtonPressed:(id)sender {
[super menuButtonPressed:sender];
[self.mapView_ removeFromSuperview];
self.mapView_=nil;
}
Say an app has two buttons and each starts an animation (eg. a push or other standard segue or custom animation). How do you stop both animations from happening simultaneously if the user presses both buttons “at once”? Well, first I tried:
[[viewController view] setUserInteractionEnabled:NO];
But this doesn't fix the problem. (Maybe userInteractionEnabled is not cascaded to subviews immediately?)
Then I tried:
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
Which does fix the problem, except if you press both buttons very quickly, one after the other (basically press both at the same time using 2 fingers), then you get both animations happening which causes problems for my app. Maybe both events have already triggered before my code to run -beginIgnoringInteractionEvents gets called?
What is a reliable way to immediately stop any other tap events? Or flush out ones that have started already. I have this problem all over my app - pressing two buttons (or tapping table cells etc) very quickly triggers two events and messes up animations.
Any ideas? What do people do about this problem in iOS apps?
Touch handling is done asynchronously in iOS to make sure the device is responsive. This means that handlers might be queued up before being run, which is the reason why your call to beginIgnoringInteractionEvents is being ignored.
The easiest solution is to simply create a global variable to make interactions exclusive yourself.
#interface UIApplicaiton(AnimationsInProgress)
- (BOOL)isAnimationInProgress;
- (void)setAnimationInProgress:(BOOL)value;
#end
And the implementation:
#implementation UIApplication(AnimationsInProgress)
{
BOOL _isAnimationInProgress;
}
- (BOOL)isAnimationInProgress {
return _isAnimationInProgress;
}
- (void)setAnimationInProgress:(BOOL)value {
_isAnimationInProgress = value;
}
Use it almost like you would beginIgnoringInteractionEvents, at the top of your animation actions:
if ([[UIApplication sharedApplication] isAnimationInProgress)
return;
[[UIApplication sharedApplication] setAnimationInProgress:YES];
[UIView animate .... completion:^{
[[UIApplication sharedApplication] setAnimationInProgress:NO];
}];
As there is no race-condition like with the touch events and beginIgnoringInteractionEvents, this will work for your purpose.
I am making a Login Screen for my ViewBased Application.I am having a problem, when i click on the UITextField the onscreen screen pops up as it should. But when i am done with typing the Onscreen Keyboard is not removing from the screen.
Can any one suggest me how can i solve this issue?
Thanks in advance
set the delegate of the UITextField to ViewController class. Override textfieldShouldReturn and call resignFirstResponder...
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return NO;
}
EDIT:
After seeing the comment It seems you are a beginner...This blog post tells about UITextField and delegates..Also when you have time, please read this post too (to learn about protocols and delegates..)