Incorrect behaviour UISearchDisplayController. Please see screenshots - ios

I need to resize UISearchBar of UISearchDisplayController. How can I do? Please see screenshots.
normal state
state after appearing UISearchDisplayController

Ok I faced the same problem few days back and came with a work around
The problem occurs because the UISearchbar tends to take the superview's width after canceling the search. this can be avoided cleverly by giving your Searchbar a superview of desired width
I am using the nib to do that.
I took a UIView with the required size
and added the 'UISeachbar` as a subclass to the view.
once the cancel is pressed the searchbar will now take the width of superview (which is a view of your desired size.)

Related

iOS 9.1 UIScrollView leaving blank space

I have a ViewController with a hierarchy as follows:
UIViewController
UIView
UIScrollView
UIView
UIImageView
UILabel
The layout is such that the UIScrollView fills the screen. There is no extra logic executed on this ViewController, such as programatic scrolling, listening to scrolling, etc.
When I run this on an iOS 9.0 simulator, the layout is correctly inflated, with the UIImageView drawn flush against the top margin.
But when I run this on an iOS 9.1 simulator, there is initially a large whitespace between the top margin and the image. Upon touching the UIScrollView it corrects itself, scrolling that the UIImageView is flush against the margin.
Setting automaticallyAdjustsScrollViewInsets does not have an effect (presumably because the scrollview isn't at my root).
My question is: What is different about iOS 9.1 scrollviews that it would be causing this, and what is the work around? Its bothering me since this isn't exactly a complex layout I'm trying to use.
Edit
Screen shot of my hierarchy and the constraints applied to them, maybe it helps.
I think the issue might be the hight constraints. try getting rid of them and add them back in, one at a time as needed.

UITextView Scrolls to the right when it gains focus in Swift

Whenever I tap on my UITextView on my testing device, the text is pushed far to the right as demonstrated in the gif below.
I can't see why this behaviour is happening, within my Storyboard I have tried to disable scrolling and have applied constraints to ensure that the width of the UITextView is only ever the width of the device, yet this still happens. The UITextView has not been subclassed or had any additional attributes applied to it via code.
If anybody has had this problem before it would be great to get some insight around how I could remedy it.
EDIT Constraints for the text view.

Swift - Can't understand the contentSize of a UIScrollView

Hi I have set in my storyboard a UIScrollView (of the same size of the view) and ctrl-dragged it in my code.
Now I have created a button programmatically using a simple algorithm of mine.
I then tried to
println(button.frame.origin.y)
which printed 1700.
Then I tried
println(button.frame.height)
which printed 142.2 (also coming from the algorithm). So the heigh I would like to reach while scrolling is 1700 + 142.2 = 1842.2
So i tried to hardcode the content size in this way
self.scrollView.contentSize = CGSize(width:self.view.bounds.size.width, height:2000)
But when I run the app I can scroll no more than the middle of the button, which is in numbers
1700 + 142.2/2 = 1771.1
Why the heck is that?
I did all this to try to understand how this UIScrollView works but I can't figure it out.
EDIT
Added a screenshot.
Inside the bubbles there is the button.frame.origin.y value. That's the max I can scroll leaving the screen untouched.
This is probably to do with scroll view insets - a mechanism where the edges of the content always appear under the navigation and toolbar.
You either need to manually account for this by reading the contentInset property of the scroll view, or using interface builder.
Scroll view Reference:
https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/UIScrollView_pg/CreatingBasicScrollViews/CreatingBasicScrollViews.html

UIScrollView & AutoLayout - UIScrollView Over scrolling (showing excessive whitespace at bottom)

I have a login page with a bunch of elements on it:
UIScrollView
Content View (UIView)
Email Text Field
Password Text Field
Login Button
Etc.
I need my app to run perfectly in both portrait and landscape orientations so I began setting up the different constraints to get AutoLayout working properly. I finally have all my UI elements in the right positions for both Portrait and Landscape, but the issue is that my scroll view scrolls too much and leaves a lot of empty white space at the bottom of the view when fully scrolled. I would like to fix this and keep things tight but I am not sure why. It's clearly the contentSize of the scrollview that is being set too large for the y value but I do not want to fix this with a workaround programmatically as I'm sure there should be the "correct" fix out there.
I've attached screenshots of the login page normal and fully scrolled (portrait and landscape) to help further understand.
Any help would be greatly appreciated. Thanks!
To adjust the height of scroll view, you need to do these two things:-
In the size inspector of scroll view, change the intrinsic size to "PlaceHolder".
Make sure you have added enough constraints that height of scroll view can be calculated. Since the contents in your scroll view are of static height, you can simply add a height constraint to your scroll view.
I'm not a 100% sure of this, but it could be that the view extends over the nav bar, causing the scrollview to have a much larger height than it should. IF that is the case, then autolayout-ing your view cause elements to be displayed everywhere else, other than the places you want them to be.
You'll need to disable Extends Under Top Bars in the attributes inspector.
I too had problem with scrollview my problem was that in iOS8 the scrollview was leaving some white space from top. I got crazy, finally I saw the solution by Ali Awais in this post and it fixed it
Here is the solution and link by Ali
I faced the same issue in iOS 8, following is solution I found: - Select View Contoller (in storybord) in which you have added the scroll view - In "Property Inspector" in "Layout" section un-check "Adjust Scroll View Insets"
White space scroll view
-anoop

UIScrollView unwanted scrolling after addSubview or changing frame

I have a UIScrollView filled with subviews, all is well when creating it and initially filling it.
But when I add a new subview that is positionned outside of the visible screen portion, or when I just resize an existing subview that is also outside of the visible screen portion, there is a subsequent 0.3s-long scroll animation (I can see it happening from my delegate) that seems to match the newly added/resized element.
Attempts:
pagingEnabled is always NO.
Setting scrollEnabled to NO during subview manipulations doesn't help.
Doing a setContentOffset:animated:NO after subview manipulations doesn't prevent the animation.
One single giant subview with all my subviews in it doesn't help.
My current workaround is to initially set the frame to fit inside the visible screen portion, or doing resizing work inside another superview, but it feels dirty, and won't handle all situations...
Is there a way to prevent this automatic scrolling animation when programmatically manipulating subviews?
Xcode 4.3, iOS SDK for 5.1.
I too discovered this problem and found this solution http://www.iphonedevsdk.com/forum/iphone-sdk-development/94288-disabling-uiscrollview-autoscroll.html
It involves subclassing the UIScrollView and entering no code in the following method.
- (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated {
}
Like the guy says on the link I've found it works and no problems so far. Hope it works for you.
I had this problem because I set the content size of the scroll view prior to adding the subview.
As soon as I change the code so that the content size of the scroll view was set after adding the subview the problem went away.

Resources