I have UIScrollView that is a subview on my view controller, in this scroll view I have UIView on top (the blue square) and a UITableView on the bottom (the light grey square). I also have a UIView that is acting like NavigationBar (the dark blue color bar), he is outside of the scroll view.
The view controller hirarchy is:
- view
- UINavigationBar
- UIView (as navigation bar)
- UIScrollView
- UIView
- UITableView
My problem is that something pushs the UIScrollView scroller down, but the UIScrollView y is where it should be, I don't know what causing it, also tried every AutoResizing mask combination, but without success, it just won't move. I also canceld AutoResizingSubviews and set AutoResizingMask to UIViewAutoResizingNone.
In the picture the scrollview is scrolled all the way to the top, you can see that the scroller itself is located down from the scrollview top. also I have a spare in the bottom exactly as the size of the padding in top.
What can I do to fix it?
In iOS 7 and xcode 5 there is new property for viewcontroller that perform such action, if dont want to see that you have to uncheck that property and then the scrollview will work fine.
In the layout section, uncheck the Adjust Scroll View Insets option and viola it will work just fine
Update: Use this code.
self.edgesForExtendedLayout=UIRectEdgeNone;
self.extendedLayoutIncludesOpaqueBars=NO;
self.automaticallyAdjustsScrollViewInsets=NO;
Related
I have a UITabBarController with one UINavigationController holding a UIViewController as root view controller.
when tapping one of the button in the UIViewController, I push a regular chat window UIViewController (with TableView + Input View) end hiding the bottom tab bar. (using the "Hide bottom bar when pushed" flag)
In storyboard I added a regular UIView subclass to VC that look like a bottom bar, and I use Auto Layout to pin it to the bottom of the VC view.
The problem
when I push VC it takes a second for this view to pin to the bottom, it looks like auto layout pin it to the bottom as if the tab bar is not hidden and after a sec it recognise that the tab bar is hidden and moves it to the real bottom of the view.
For clear info check this screen shot
Now I will let you the know the constraints of the table view..
Now I am showing the constraints of the InputView
I am also adding my View hierarchy...
I had a similar issue in my project. I solved it by selecting the view I wanted anchored to the bottom (in your case, the input view), held Command, and selected its superview (both views should be highlighted now).
Then I selected the align button at the bottom of IB:
And added a Bottom Edges constraint.
What I had done initially is used the pin menu to pin the view to its superview, but it appears that will pin it to the bottom layout by default, which causes that weird movement during the transition.
EDIT:
After seeing the latest screenshot, the problem could lie in one of the superviews. I'm assuming that chatWindow is a UIView, and your Scroll View is horizontal only. Here's what your should check:
chatWindow is pinned to the scrollView's bottom similar to what I've outlined above.
scrollView is pinned to its superview as I've outlined above.
Moving the inputView outside of the scrollView to the root superview. Then one by one move it down the hierarchy towards its current location.
I have a modal view that I'm presenting over the current view that has a UINavigationBar as a subview. Everything's working great, except that the UINavigationBar doesn't want to behave according to the autolayout constraints. Everything else in the view behaves as desired.
For some reason, the left and right bar button items are cut off on the edges of the view. I inspected the view at runtime to reveal that the total width of the UINavigationBar is the right width, but the bar buttons aren't conforming.
I also checked to make sure I didn't have negative margins or some other anomaly in the constraint definitions.
I have also tried setting the frame of the UINavigationBar manually, but it yielded no improvement.
Problematic View
Constraints
I'd like to keep the UINavigationBar, because it gets styled globally with the rest of my app (as opposed to creating a custom UIView imitation and styling it individually). Does anyone know what handle to jiggle to get the bar button items to conform to the right width?
I have a problem with sendSubviewToBack and bringSubviewToFront calls. I create UIImageView and ScrollView with several other elements (like buttons and labels) programmaticaly (only ScrollView is created in storyboard). UIImageView have to hold a background image. ScrollView and UIImageView are added as subviews of view controller (other elements are subviews of scrollview). After I create a UIImageView and set the image like this, I call
self.backgroundImage = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height)];
[self.backgroundImage setImage:[UIImage imageNamed:#"chooseDoctorBackground"]];
[self.view addSubview:self.backgroundImage];
[self.view sendSubviewToBack:self.backgroundImage];
After that, scroll view "moves up" and becomes overlapped by navigation bar (it doesn't happening if we won't call sendSubviewToFront). There is an easy workaround - just to define position of UIImageView and UIScrollView explicitly (using setFrame) with consideration of navigation bar and status bar height. However, I don't understand the root cause of such behavior. Could you please explain it to me?
Thanks in advance!
I came here looking for help with a similar issue, and have since figured out the cause of both our problems:
When a UIScrollView is the back-most subview of your view, iOS will auto-pad the UIScrollView's content to account for the status bar and navigation bar. That is why your scroll view's content appears fine at first.
When you call
[self.view sendSubviewToBack:self.backgroundImage];
your UIImageView becomes the back-most subview, and the UIScrollView ceases to get auto-padded. That's why the content of the UIScrollView moves up underneath the navigation bar.
You'll need to manually set your scroll view's frame or content offset to account for the status and navigation bars in order to support the background view appearing behind.
(In my experience, this auto-pad behavior on UIScrollView happens even if the y origin of the scroll view is non-zero and it sits lower on the screen, nowhere near the status or navigation bars.)
I have xib in which button and uicollectionview appears as follows:
Now, when I run it , it appears as follows:
I want to remove white space above photos. I want to show photos just below from button. I have not marked header section in xib too. But, when I scroll up, the images move upto just below buttton too.This means frame is starting from just below button, but, I am getting extra white space.
So, can anybody help me to remove extra white space?
Add this code to your Controller class
- (void)viewDidLoad
{
[super viewDidLoad];
self.automaticallyAdjustsScrollViewInsets = NO;
}
Here is doc for automaticallyAdjustsScrollViewInsets
Default value is YES, which allows the view controller to adjust its scroll view insets in response to the screen areas consumed by the status bar, navigation bar, and toolbar or tab bar. Set to NO if you want to manage scroll view inset adjustments yourself, such as when there is more than one scroll view in the view hierarchy.
I had the same problem. What work for me was to set automaticallyAdjustsScrollViewInsets = NO not only on the ViewController containing the CollectionView but on its parent ViewController too, because the child ViewController was in a ContainerView.
It can be done in the Interface builder too:
Auto adjust scroll view insets
I have a UITableViewController in a Storyboard that I'm adding as a subview to a lone UIView in a UIViewController, my end goal is to get the UITableView flush up against the status bar so that scrolling goes underneath the status bar (not through it with clashes).
I have configured the lone UIView to have constraints of 0 on both verticals and horizontals but as demonstrated in the image I believe autolayout is then adding the 20px y offset that I am including in the layout. If I remove the 20px y offset (and size the UIView to the whole layout) I end up with the clashing.
I suggest you to set up your view controller as follows. Create a UIViewController in IB and add a simple UITableView as a subview of its main view. I almost never use the UITableViewController because it has almost no added value but it restricts you in adding subviews to your table view. Now, you position your table view's origin to (0, 20) and set up the top layout constraint of the table view to the top layout guide instead of the superview. Maybe you should open the drop down menu close to the constraint constant value in IB:
This way your table view will start right under the status bar.
Note however that iOS 7 design guidelines suggest that you would in fact extend the content under the top bars (nav bar and status bar). You should create a 20 points high semi-transparent background png, position it under the status bar, and leave the table view to scroll under the status bar. In this case you should also not forget to check in the "Adjust scroll views inset" option of your view controller.