iOS keyboard appearance messing up other view - ios

I have UITextField, UIButton and UIImageView inside my view. On viewDidLoad I am animating (moving up) button and image and setting them on some specific position. But when user taps on a textfield to edit it, as the keyboard appears the button and image move back to their original positions.
I don't want any view to move back after my animation finishes. The keyboard appearance is messing up my views. Why its happening or how can I prevent it from happening?

Related

Keyboard flashes from opaque to transparent upon push

I have a view embedded in a navigation and tab bar controller. When a button is pressed, it pushes to (shows) the next view and I programmed the keyboard to immediately show for the first text field [textField becomeFirstResponder].
However, the keyboard will be opaque instantly then turn transparent in a little less than half a second. This happens no matter the keyboard type or keyboard look. I have no idea what is causing this, and I cannot find any answers anywhere else.
Other details: the navigation bar is translucent, and the bottom bar is hidden on the view we push to. The background is an image. This problem does not occur if I remove [textField becomeFirstResponder] and have the user just select the text field, but that is not what I am trying to do.
I have a similar scenario and also ran into this issue.
I am push-segueing between view controllers, and the keyboard has to stay up during the segue (textField.becomeFirstResponder() is called in viewWillAppear(_:)). The view controllers' background is white, but the keyboard look is Dark. During the segue, the keyboard is black, and then turns gray as soon as the segue finishes.
I came up with a workaround for that - it works if you want to have the keyboard opaque-ish at all times.
Add an empty UIView to the view controllers where you want to show the keyboard instantly, and set the backgroundColor of the view to match your keyboard's look (black for Dark, white for Light). Pin that view to left, right and bottom edges of the view controller's safe area superview. Add a height constraint to it equal to 0 and make an IBOutlet for it.
In your view controller, subscribe to KeyboardWillShow and KeyboardWillHide notifications and control the height constraint of the view you created - make it match the keyboard's frame height (the keyboard's frame end).
You will still see that during the segue, the keyboard stays opaque, but when the segue finishes and keyboard transparency kicks in, the effect is much less visible.
Ideal scenario for me would be to be able to turn off the transparency of the keyboard completely, but I don't think it's possible. I also think there is no way to make the keyboard non-opaque during the segue, so the only option is to make it look opaque at all times.

How to scroll within a ScrollView while keyboard is present?

I have a ScrollView and two buttons, one is at the top of the view and the second one is set lower than the height of the keyboard. By changing the inset, I now have the ScrollView move up once the second button is pressed and the keyboard is shown. However, after I press the second button and the keyboard moves the ScrollView up, I want to scroll the view up with a touch to be able to see the first button (without closing the keyboard). But whenever I try to pull it up the keyboard disappears. Any thoughts?

UIKeyboardTypeNumberPad hides bottom of view

Newbie alert...
I'm updating some code that has a UITextField with a keyboardType of UIKeyboardTypeNumberPad. In the view, which is in a UIScrollView, there is also a save and cancel button below the textfield. When you tap the textfield, the cancel button is not visible and you cannot scroll to it.
Is there a typical approach for this scenario to make the cancel button accessible when the keyboard pops up?
Is the idea to just manually increase the UIScrollView content size when the keyboard displays and then decrease it when it is dismissed or is there a simpler way of achieving this?

Present UIPopoverController from a moving rect

Just got this weird problem, where I have a scroll view and buttons in the scroll view. I want to display a UIPopover from the button when touched, with UITextFields inside the UIPopover. The problem comes when the Keyboard appears. In certain cases, when the UIButton is so high in the view that the popover can only be displayed under it with the UIPopoverArrowDirectionUp, and when keyboard pops in, this popover cannot move any more up and therefore magically disappears to the top left corner (probably some Apple thing).
My solution is to check the frame of the UIPopover and to check that there is enough space for the keyboard, and if not, scroll the UIScrollView up with the buttons as well in order to be able to push the UIPopover up and so make sure that both the Keyboard and the popover fit.
So the question is: Is it possible to move the popover as the button moves?
Thanks

How do I make my UITextView autoscroll when dragging caret to the edge of view?

In the iOS's Notes app, I wrote very long text on the TextView,
then I long press on the view, bring up the magnifier loupe, drag it to the bottom of screen (or top of the keyboard, if it is activated), the TextView will automatically scroll up.
How can I implement this with UITextView?
I tried
Add a UILongPressGestureRecognizer to my UITextView subclass, but its action never get called.
Override touchesMoved:withEvent: method in my UITextView subclass, but this method will not be called after the magnifier loupe appears.
You don't implement it; that's standard behaviour.
The magnifier scrolling occurs when you drag the magnifier off the bottom or off the top of the UITextView, or when you're close on the edge, about 10 pixels? (best to test this in the simulator where to have exact-control over the touch-position). If your text view is full-screen you may not be able to drag to a position outside the view, and the touch-region for scrolling may just be too small.
Notice in the Notes app that to scroll down you can drag the magnifier onto the tabs at the bottom. To go up you can drag it into the title. So long as you hold the touch outside the view it'll scroll.
All this also means your view can't go behind the keyboard when it's present. You need to resize the UITextView when the keyboard appears to get the scrolling to work.

Resources