UICollectionView default margin whith UINavigationBar translucent - xcode8

i'm having problems with UICollectionView.
The first cell to be displayed has an upper margin of the same size as the height of the NabigationBar, but only if the NavigationBar is marked as translucent.
I show you some screenshots from my Storyboard.
When is translucent
When is not translucent
As you can see the cell has no upper margin when navigationbar is not marked as translucent.
HELP ME PLEASE :(

The problem was because of the constraints.
The CollectionView top constraint was in relation with top layout guide, and must be in relation with View(superview), because "Top Layout Guide" changes when Navigation bar changes.

Related

UICollectionViewCell size zero in storyboard

I dragged the UICollectionView in the storyboard , The UICollectionViewCell size then changed to 0,0,0,0.
The height of the UICollectionView is 0,64,375,60.
The height of CollectionView cell is , with deducting top spacing(5) and bottom spacing(5). i.e Size is (55,55)
The scroll direction is horizontal.
Don't know why I don't see the cell.
My Further findings , I found if the CollectionView is outside the View(green border), then it shows up fine. But as soon as I move inside that view the UICollectionViewCell disappears.
Finally found the issue. The problem was Adjust Scroll View Insets of that viewController was checked.
Unchecking that option, solved my issue.

UIScrollView Failing to Scroll

I have a UIScrollView with a fair bit of content in it. The structure is shown below:
However, my scrollview isn't allowing a scroll to occur. I have made sure AutoLayout is off and the scrollview is larger than the screen size. The ScrollView isn't altered in the .h or .m files in any way. Any ideas why it may not be scrolling? The settings are default for the scrollview (essentially dragged and dropped in IB). ScrollView sizes as below
Your UIScrollView should be equal to or smaller than your screen. The content of your scroll view should be larger than your scroll view's frame. (It is the content of the scroll view that scrolls within the bounds of the scroll view's frame.)
Then, in code, do something like this:
[scrollView setContentSize:CGSizeMake(contentWidth, contentHeight)];
[scrollView setScrollEnabled:TRUE];
The scrollView should (typically) NOT be larger than your screen size.
It's NOT the scrollView that scrolls, it's the content IN the scrollView that scrolls.
So set the contentSize of your scrollView to the appropriate size of your content and keep the scrollView itself within the bounds of the screen.

UINavigationViewController changes the behaviour of scroll view in iOS7

I have a 'UIScrollView' that is supposed to display a list of images one next to the other. This is the code I'm using to add each image:
#define SCROLL_PADDING 10
#define SCROLL_DIMENSIONS 50
view.frame = CGRectMake(xValue, SCROLL_PADDING, SCROLL_DIMENSIONS, SCROLL_DIMENSIONS);
[scroller addSubview:view];
However, as shown in the image below, the images are loaded with a vertical offset. After some research I realised that this offset is the same as the height of the navigation bar's height.
Note 1: By default the images cannot be seen. I had to scroll up to make them visible.
Note 2: I shouldn't be able to scroll because the images should fit in the scroll view.
I decided to present the view controller modally instead of pushing it to the hierarchy of the navigation view controller and everything work as expected.
This problem only happens in iOS7. Any ideas why?
I came across this article, which clearly explains various changes in status bars and navigation bars on iOS7
As you can see in both of the images above, the position of the scroll view doesn't change. In iOS6 if the subview's frame doesn't change, it would be moved down to prevent it from underlapping the navigation bar. Since iOS7 it is expected that all subviews will underlap not only the navigation bar but also the status bar, which makes the location (0, 0) the top left of the SCREEN.
For some reason that I don't understand yet (it would be nice if somebody could explain), only the scroll view's subviews where moved down in the same way it was being done in iOS6. Hence making the subviews appear out of the scroll view's bounds.
To prevent the subviews from underlapping the navigation bar it is necessary to set edgesForExtendedLayour to UIRectEdgeNone as early as possible in the life cycle of the view controller
viewController.edgesForExtendedLayout = UIRectEdgeNone;

Navigation bar with coloured translucency over a map

I've a view with nothing but a map on it, inside a navigation controller.
The navigation bar is translucent so the map can be seen slightly through it.
This works fine with the navigation bar tint set to Default, but as soon as I change the bar tint to a specific colour the navigation bar background turns completely transparent.
Interestingly, the issue doesn't happen in the emulator, only on an actual iPhone (a 4 (not S), in case that might be relevant).
I've added no code yet- everything I've put together was generated purely in Interface Builder.
Does anyone have any idea what might be happening here and what I might be doing wrong? Or is this a bug I need to report to Apple?
You need to set the bar's translucent property to true. From the Apple documentation for UINavigationBar:
barTintColor
The tint color to apply to the navigation bar background.
This color is made translucent by default unless you set the translucent property to NO.
When you set a tint color on a UINavigationBar, it sets translucent to false. Unfortunately, translucent can not be set on an appearance proxy. You'll need to add self.navigationController.navigationBar.translucent = YES in all your viewWillAppear: methods (or create your own subclass that changes the default)

UIScrollView auto scrolls to bottom during change to landscape orientation

I have a scrollview with 2 UITextViews (neither are editable). When a change to landscape orientation occurs, the scollview inexplicably scrolls to the bottom. This behaviour does not occur when rotating to portrait. I have tried setting the scrollEnabled property before rotation to NO, but to no avail. Any help would be appreciated please.
I eventually found that by setting the scrollview contentsize to 0 before rotation and restoring it during or after rotation prevents this unwanted auto scrolling