Swift - Remove default "Go-to-top-on-active"-function from UISearchController - ios

By default a UISearchController moves to the top of the screen, when you click on the textfield. Is there a way to prevent this action from happening?

You should be able to prevent this behavior by setting a certain property on the UISearchController:
self.searchController.hidesNavigationBarDuringPresentation = false
More detail on this property is available in Apple's documentation

Related

iOS13 - UITableView + UISearchController with custom hidesSearchBarWhenScrolling behavior

On iOS 13, if you set hidesSearchBarWhenScrolling to true, the view controller will hide the search bar, and you have to scroll down to reveal it.
If you set it to false then it is immediately shown and it won't disappear.
I think this is a reasonable behavior, assuming that the end users are all versed in the way the Apple products work. Given that's not seem to be the case, I would like to show the searchbar at first visit, but then if the user starts scrolling up, the search bar is hidden. So this is a mixed behavior of the true/false.
This worked on iOS12, where I set the hidesSearchBarWhenScrolling = true in the viewDidAppear, but now on iOS 13 it's not the case. The table scrolls, but the searchbar stays on top instead of scrolling it together with the tableview(btw this is only because the screen is not rendered again).
Any idea how to go about it? I tried changing the content offset of the tableview, but no luck really.
For me it worked after adding following lines in viewDidLoad() method:
navigationController!.navigationBar.sizeToFit()
No need to specify hidesSearchBarWhenScrolling as I think by default it is true, but if you still see the search bar then you can set it true to hide it.
I faced the same issue as you and looks like such issue appears in iOS 13 only. In iOS 14 your solution works perfectly.
To make it work in iOS 13 you need to add
self.navigationItem.hidesSearchBarWhenScrolling = true
self.navigationController?.view.setNeedsLayout() // add this line
in viewDidAppear
It works for me in simulator iOS 13.7 I hope it work for you as well.

UISearchController extra unexpected UIView in hierarchy

I have problem with UISearchController. It is adding one extra View as direct child of its View. It has isAccessibilityElement = true and description "Double-tap to dismiss", this blocks all Appium automatic testing. I can't figure out why, where and how it is added.
Someone know when and why this view is added and how to remove it? I have tried to set its isAccessibilityElement = false form code but somehow it is set back to true in some cases.
For anyone else who has this issue. It's caused by the default behaviour Apple have given the UISearchController where the searchResultsController is initially hidden until the UISearchBar has text.
We had old code in the searchResultsController to unhide itself view.isHidden = false which fought this default logic.
The fix was to remove this and instead set searchController.showsSearchResultsController = true which shows the results always and doesn't add the double tap to dismiss view.

Disable VoiceOver on a MapView [duplicate]

When I set isAccessibilityElement = NO on a view that contains subviews with isAccessibilityElement = YES, VoiceOver still detects them.
I need to switch off accessibility for an entire view hierarchy that must be handled differently by VoiceOver. How can I achieve this without having to loop through every single item in the object graph and mess with it's setting?
self.accessibilityElementsHidden = YES;
This makes all subviews hidden from accessibility.
I would try setting the accessibilityElementsHidden property of the main view to YES. If that does not what you want, I would try overriding the UIAccessibilityContainer methods on the main view to return 0 children.
Just set the accessibilityElementsHidden property.

Tweak UI Navigation on iOS 11

I have a problem with a navigation bar in iOS 11.
I use this code:
[UINavigationBar appearance].prefersLargeTitles = YES;
...to set a new style for my app. It works well untill a user pull to refresh on the table view; then it breaks.
This is before pull-to-refresh:
...and this is _after:
Note: I use the table view controller's built-in pull-to-refresh control.
I searched for a solution but it still eludes me. If someone knows how to fix this please drop some advice.
Thanks for the support :)
I have catch this bug too, and we have found the solution.
You must constraint your UITableView to superview (contentView of your view controller), after that large title and all related views starts to work correct.
Like this:
While I do not claim this is the solution for every situation the error occurs in, setting the navigationBar's isTranslucent property to true (which is also the default value) fixed the problem for me.
If you want to keep your navigation bar non-translucent you can use the following code:
navigationBar.barStyle = .blackOpaque

ios uibutton hidden: does this automatically make the button disabled?

I just have a knowledge question about UIButtons / iOS in general.
Let's say you have a UIButton. You set the 'hidden' property to YES. This makes it no longer visible in view, right? But I noticed that while it's no longer visible, it is also no longer clickable either. So, does this mean that setting hidden = YES also sets enabled = NO?
Just curious. Thanks y'all.
UIButton and all controls inherits common properties from UIView like hidden, backgroundColor, etc.
Class reference of UIView says if any view is hidden then it will not receive input events
Class reference of UIView says:
A hidden view disappears from its window and does not receive input
events. It remains in its superview’s list of subviews, however, and
participates in autoresizing as usual. Hiding a view with subviews has
the effect of hiding those subviews and any view descendants they
might have. This effect is implicit and does not alter the hidden
state of the receiver’s descendants.
you can find this over Here.
It does. Setting the buttons hidden property to YES will disable any user interaction. This is true for other UI elements as well as just UIButton.
Yes you can't touch button when it is hidden.If you wanna touch it then you must make it btn.hidden = NO;. Hidden means disable the user interaction.
Not sure. Best way to find out would be an NSLog returning button.hidden

Resources