UITextFieldViewModeWhileEditing change my TextField frame - ios

I got an weird issue. Please help me in this case.I had a bottom View which contain a TextField like this image
When I type text in textfield, I want my bottom view move above the keyboard and be like this:
However, after typing one character, my bottom view will move back to this previous position
I found out that whenever I set
self.textField.clearButtonMode = UITextFieldViewModeWhileEditing;
my bottom view will move back to its previous position.
This is my source code link: https://github.com/duythuc28/ProblemUITextField
Thanks for your help.

First of all, change observers from UIKeyboardDidShowNotification to UIKeyboardWillShowNotification and from UIKeyboardDidHideNotification to UIKeyboardWillHideNotification. Second: don't change view's frame. You have bottom view's constraint to bottom (equal to 0); create outlet for this constraint and in method keyboardWillShow set it equal to keyboard height and in keyboardWillHide to 0.

You are using Autolayout, so you cannot set frame for the view. It should reset the constraint.
Or you can use third-party such as IQKeyboardManager to handle your keyboard event with worries free. IQKeyboardManager can be used in both ObjectiveC and Swift. It can also handle the appearance of the suggestion on keyboard (which I realize in your code that haven't handled yet) Here is the link: https://github.com/hackiftekhar/IQKeyboardManager

Related

UIModalPresentationPopover - arrow direction Up, Prevent Contentview from starting from tip of the arrow

in iOS 13 it happens that the view of UIViewcontroller that is presented as model starts from the tip of the arrow. Because of it top banners in all of my popover gets cut. Can I prevent this from happening ? I want that my UIView does not start from arrow but once arrow is finished.
To fix this issue, I opened up my view controller's XIB, selected the top-most view, and then checked "Use Safe Area Layout Guides" under the File Inspector. Then I added Auto Layout constraints (of length 0) around that view's sole subview (a UITableView).
(I also needed to update the view controller's background colour. This changed the arrow colour back to what it was in iOS 12 and before.)
Background: https://forums.developer.apple.com/thread/122703
I wonder if your contentView contains UIScrollView. If yes, please add alwaysBounceVertical = YES to your scrollView. It works in my case.
I don't know why they changed this behavior, it can be a pita to deal with it if you are not using xibs. I couldn't find anything in the docs about it.
Use the safe areas to adjust the position of your view. You can both try to extend the size of that red area, or skip the arrow completely. In this particular case you can use safeAreaInsets.top if the arrow is going to be on the top always.

StatusBar Padding automatically added on setNeedsLayout

I want to display a ViewController from the bottom over the current ViewController, with a specific height. Then I added the ability to move the ViewController up, all the way behind the StatusBar. I implemented it with a UIPresentationController. It looks like this:
And now I have a big Problem: When I set a new Value to any label, the method setNeedsLayout gets called and the view of my presented ViewController adds padding of 20px to the top. It looks like this:
My Aim is to set the new Text to labels without triggering this padding insertion. Why is it even added? I tried setting the frame and bounds of the view manually, but it didn't work. The property automaticallyAdjustsScrollViewInsets didn't help either.
After some research I found out that I just could override the prefersStatusBarHidden method. By doing this, the status bar went away. Because the dialog is modal, I needed to add myDestinationController.modalPresentationCapturesStatusBarAppearance = true to make it work.
I hope it helps some people in the future!

iOS 8 get keyboard height

I'm having trouble reliably getting the actual height of the keyboard. I'm adding a custom toolbar that is meant to be placed directly above the keyboard. To do so with layout constraints, I've added a static space constraint between the bottom of the screen and the bottom of the toolbar. When the keyboard is displayed, I modify this constraint to be the height of the keyboard, which varies quite a bit in iOS 8.
To resize the spacer, I currently use the following method that gets fired on UIKeyboardDidShowNotification
-(void)keyboardDidShow:(NSNotification*)notification
{
CGFloat height = [[notification.userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].height;
self.shimConstraint.constant = height;
[self.view layoutIfNeeded];
}
This does resize the constraint correctly sometimes, but often the keyboard height returned is entirely incorrect. What is the best way to reliably get the height of the keyboard once it is displayed?
EDIT: The application allows the user to switch between a number of different input fields. Some of them have autocorrect disabled, so the autocorrect bar may or may not be hidden, and incorrect heights are returned when switching fields.
The way you are doing it is correct but you might want to use UIKeyboardFrameEndUserInfoKey instead of UIKeyboardFrameBeginUserInfoKey. The end user key is the frame of the keyboard when it is done animating and on the screen, thus you know it will be that frame, while the begin key might not always match what the keyboard frame will be when it is shown.
There might also need to be extra considerations on orientation of the device, I have not looked into that, but for portrait, it should work.
The correct way to do this is to use the inputAccesorryView property of the UITextField.
The inputAccessoryView is automatically added above the keyboard regardless of keyboard size.
As the documentation states:
The default value of this property is nil. Assigning a view to this property causes that view to be displayed above the standard system keyboard (or above the custom input view if one is provided) when the text field becomes the first responder. For example, you could use this property to attach a custom toolbar to the keyboard
See more information here
https://developer.apple.com/library/ios/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/InputViews/InputViews.html
You might need to do [self.view setNeedsLayout] instead of [self.view layoutIfNeeded].

The frame of uitableview is not changing programmatically

I have 2 UITableView in my UIViewController. one of them is in the right side of the screen till center of screen. The other is from center till left bound.
User can hide the right UITableview by pressing one a button on the navigation bar.
I use this code to make left UITableview full screen:
self.rightTableView.hidden= YES;
self.leftTable.frame= CGRectMake(0,
self.dataTableView.frame.origin.y,
self.view.frame.size.width,
self.dataTableView.frame.size.height);
But it is not working.
I even put this code on the viewdidload and viewDidAppear methods but the frame not changing.
Try self.leftTable.translatesAutoresizingMaskIntoConstraints = YES, then call to frame resize at runtime is automatically translated into new constraints.
But, translatesAutoresizingMaskIntoConstraints will also cause new constraints to be added based on the view's autoresizingMask. So make sure other constraints are working properly.
When using autolayout, modifying the frame will have no effect.
Instead, you should modify the constraints.
You can do this by creating outlets for your constraints and connecting then in the interface builder.

How to make keyboard move along with scrollview?

I have a scrollview and a searchbar in a controller. And I want the keyboard move along with the scrollview when the scrollview is being dragged. Just as when edit a message on iphone.
So what should I do and I will appreciate it if you can give me some code.
What I mean is when the searchbar is the first responder,there will be a keyboard ha ?
And if I scroll the scrollview ,the keyboard will move along with it.
Some one said I should listen some notification. Is it right?
Thank you very much.
You cannot move a keyboard along with the view.You can only change position of the view underneath it.Therefore, If you wish to move the keyboard along with the scroll....All You need to do is to make your own custom keyboard!!!!!

Resources