How to control UIScrollView automatically scrolling on FirstResponder / Keyboard changes? - ios

TL;DR
Is it a new feature in Xcode 14 and iOS 16 that a UIScrollView is now scrolled automatically when a view inside the ScrollView becomes firstReponder and the keyboard appears? While working on other iOS projects in earlier versions of Xcode and iOS I never came across this behaviour. Can this be controlled or deactivated?
Details:
While working with Xcode 14.0.1 on a new iOS project I noticed that an UIScrollView is now automatically scrolled when the content view becomes first responder.
Have a look at this example. I have created a new project, added a ScrollView to the ViewController and placed 12 subviews inside to fill it with some content. Subview no. 12 additionally holds a UITextField. The firstResponder status of this text field can be toggled using the top button.
When tapping on the button the TextField becomes firstResponder and the ScrollView is automatically scrolled up. However, not enough to make bring the TextField above the keyboard and make visible. Just enough to bring it above the bottom screen edge.
This does not make a lot of sense to me.
Is it possible to control this automatic scrolling or to deactivate it?
EDIT:
I have created CustomScrollView as UIScrollView subclass and did override scrollRectToVisible. When calling super.scrollRectToVisible everything works as before, but I could set a break point to see from where scrollRectToVisible is called.
The callstack shows the method scrollTextFieldToVisibleIfNecessary inside UITextField which uses delegateShouldScrollToVisibleWhenBecomingFirstResponder
However, UITextFileDelegate does not have such a method / value and scrollTextFieldToVisibleIfNecessary is also documented nowhere.
So, the question remains: How to disable this behaviour?

Related

Prevent scrollview from autoresizing

Im creating a basic messaging app with the message "bubbles" inside a scroll view. When the user first opens the screen the keyboard is not showing (besides an input box at the bottom), when they press the input box and start typing the keyboard with pop up (using NSNotificationCenter) a function will be called to resize the scrollview so that is no longer behind the keyboard.
That part all works well but when the user sends their message and a new bubble is added to the scrollview. The scrollview will automatically revert back to the size of the screen thus being behind the keyboard.
The scrollview is originally created in storyboard to take up the whole dimensions of the screen. So I suspect the cause of the resizing is due to some kind of message calling autolayout to update the scrollview when a subview is being added to it.
Im looking for a way to prevent the scroll view from reverting back to this autolayout when a subview is added to it, Thank you!
When the keyboard appears, adjust the UIScrollView's size by modifying its constraint's constants.

iOS8 When using VoiceOver content of the collection view is scrolled to beginning

I have simple collection view created programmatically with build in horizontal layout and 50 items. When I enable VoiceOver to speak content of each cell, scroll position is changed to beginning on first item.
I would like to preserve scroll position. Am I missing something when VoiceOver is enabled?
With voice over disabled it works without issues.
Good to mention it works without issues on iOS7. I am using xcode 6.

NSTextView stops being able to scroll once new text is set

I have a TextView made in the Interface Builder;
It scrolls fine with its default text, but as soon as I programatically set the text to something else, it no longer scrolls.
I do not disable scrolling, and I have tried enabling scrolling (setScrollEnabled:YES), and user interaction (setUserInteractionEnabled:YES) both of which make no difference.
The things that I have found:
It scrolls with the default text showing
It doesn't seem to matter what text I set in it, it just stops scrolling as soon as it is set. I'm doing it programatically like this:
self.myTextView.text = #"any text"; (or [self.myTextView setText:#"any text"]; has the same effect.)
I have two other Textfield in the same View, one of which is using the View Controller as its delegate. The TextField in question is not using the View Controller as its delegate. None of the delegate methods set anything to do with scrolling.
Both of the other TextViews have their scrolling capability set to defaults. If I change the one that doesn't need it to no scrolling, it makes no difference to the problem.
The one that has the View Controller as its delegate continues to scroll after I edit it (non programatically) and this one continues to be able to scroll once the one in question freezes.
If I delete these two other TextFields, then the one in question works as expected, i.e. it scrolls after adding text.
Any thoughts?
Thanks.
Make sure your new text is long enough to be able to get scroll.
if text is just one line it wont scroll but if its larger then text area size then it will scroll its by default settings

UIMenuController menu disappears automatically when there are multiple UITextView

I'm trying to make UIMenuController to display copy&paste menu when the UITextView got long pressed. It works if there is only one UITextView on the screen. However, if there are multiple UITextViews on the screen, long press on the active UITextView (The one is the firstResponder) triggers magnifying glass to be shown, when finger is released, the copy&paste menu is displayed, however, the menu is dismissed automatically in less than one second.
The following is the view hierarchy:
UIView -> UIImageView -> MyUIView -> UITextView
|__> MyUIView -> UITextView
I set userInteractionEnabled and editable of non-active UITextViews to NO. Any idea on how to make the copy&paste menu stay?
I am using Xcode 4.6.3 and test it on iPhone 4S with iOS 7.0
Apparently, whenever there's a change in firstResponder, UIMenuController gets dismissed!
In order to track the source of the change, if other, you can listen to UIMenuControllerWillHideMenuNotification and check who's dismissing the menu.
I found a solution. I didn't have enough details in the question, that's probably why there was no answers.
The key missing piece is that I subclassed UITextView and it overrides layoutSubviews (see buggy margin behavior with dynamically resizing UITextView). The solution is simply removing layoutSubviews function, and I used krafter's suggestion to address UITextView cut off issue.

iOS 7 tableview no longer auto scrolling when keybaord appears

I am working on an app which I have just released an iOS7 version of. In the app I have a table view that contains text feilds in each cell. The problem is that when I tab to edit a feild that is near the bottom of the screen the keyboard appears and I cant see what I'm typing. I fixed this in iOS6 by simple listening for the event of the keybaord appearing and changing the size of the tableview so that it no longer extended to the bottom of the screen, but instead only reached to the top of they keyboar. The table view would then "automatically" scroll so that the cell was visable. This worked fine in iOS6 but as soon as I made the switch to iOS7 this no longer works... it no longer "automatically scrolls" when I change the size of the table. Does anyone know if there is a property that I need to set or something to "re-enable" this functionality?

Resources