I've been using the technique of wrapping a UITextField in a UIScrollView to prevent autoscrolling, for details on this, see this discussion on SO:
Disable UIScrollView scrolling when UITextField becomes first responder
This has been working fine for some time now on iOS versions < 7. However, it no longer seems to work on iOS 7. Has anybody else encountered this? Has anybody found a fix?
Figured out what was happening ... I had code that was setting the contentOffset.y to 0.0f in certain cases ... but on iOS 7, that was causing the scroll view to scroll up too far, and it should be setting it to -64.0f. I mistakenly thought this was being caused by UIScrollView's autoscrolling behavior.
Related
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?
Strange issue faced today. Xcode 8.3.2 while using UIScrollView, UILabel shows outline and actual label on different place. Which also display weird in the simulator.
Anyone faced the same issue. Any solution ? I have searched google so much but found nothing.
Help me if anyone has solution.
When there is a red arrow in your view hierarchy:
It means something is wrong with your autolayout. Click on it and Xcode will provide you with the information what's wrong. In this case your scroll view needs to know size and position of your content (In your case size of the UIlabel), so it is able to stretch its content and determine if it should scroll.
I have a UISearchBar attached to the top of the table view. The idea is that when you drag down from the top you can search.
So under iOS 6 I have attached the search bar and then in the viewDidLoad I "setContentOffset" to CGPointMake( 0, searchBar.frame.size.height ) which sets the content offset to 44.
This works perfectly for me.
However the behaviour is not the same in iOS 7.
After I do the setContentOffset in viewDidLoad, I see an internal call to _notifyDidScroll which sets the content offset back to 0 (after viewDidLoad has completed). The funny thing is my search bar is not at -44.
How can I make iOS6 and iOS7 behave the same way? I don't care if iOS6 starts doing this notifyDidScroll or iOS 7 stops doing it, but i'd like consistency between both versions!
For now I have had to use a horrible solution that performs different tasks on iOS 7 and iOS6.
I think you need to disable UnderTopBars in your ViewController. You can do this in the storyboard or .xib in the property of your UIViewController.
edit:
Hope that will help.
I am porting an iOS 6 application to iOS 7 and have noticed some UI bugs that I have bad some issues solving. The largest would be one I found in the UITextView. In iOS 6 I have a UITextField that has a varying amount of dynamic text in it. I have a function that resizes the table view cell around the text view but I found it hard to accurately predict the size of the UITextView so I just disabled clipping and let the text overflow outside the UITextView. I put a buffer between the cell view and the text and thought the problem was solved. When I ported the application to iOS 7 this no longer worked. I can't seem to find a way to have the UITextView not clip it's subviews and overflow the text as it did in iOS 6. I have tried setting setClipsToBounds:NO both in the UIStoryboard and programatically, and have also tried disabling the layer mask with setMasksToBounds:NO. Nothing seems to work, how can I solve this problem?
Hey so I ended up fixing this issue using the iOS 7 constraints. I clipped the bottom of the UITextView to the outer view and removed the pinned height. This allowed the UITextView to resize appropriately.
I have a problem since I updated to iOS7.
I have base UIScrollView horizontally and there is UITableView on it
(looks like a navigation style).
And I addChild UITextView on UITableView not on the cells.
And it scrolled to UITextView's cursor when typing keyboard. And it works greatly until iOS 6 but not since updating iOS7.
How can I solve this problem?
Thanks.
Handle textViewDidChangeSelection in UITextViewDelegate:
- (void)textViewDidChangeSelection:(UITextView *)textView {
[textView scrollRangeToVisible:textView.selectedRange];
}
The exact solution depends on your application, you can handle by subclassing UITextView but I would prefer a decorator pattern here (on UITextViewDelegate protocol).
I hope it helps.
Have you created your XIBs in xCode4 and now trying to open it in xCode5?
If yes than please check your XIBs properly as Xcode5 updates older xCode 4.x XIBs and sometimes it results in a unpredicted output.. I faces the same issues when all my views just disappears after opening it in Xcode5..
Also do try to change the settings of the xib in File Inspector to open in xcode 4.x and view as ios6.1 and earlier and see if it changes anything..