swift: uicollectionview changes contentoffset of the cell during transition - ios

I have a simple UICollectionView with a custom cell inside of a navigationController. For some reason when I push a viewController, the collectionView cell changes its layout during the transition.
Is it some common behavior of uicollectionview during viewController transition? Because, for example: labels don't have such problem
When back button was clicked
Green color from collectionView
Adding new view controller
navigationController?.pushViewController(controller, animated: true)
Setting Autolayout using EasyPeasy pod
collectionView.easy.layout([
Top(),
Right(),
Width(view.frame.width),
Bottom(10).to(button),
])
button.easy.layout([
Center(),
Height(60),
Width(300),
])

I think I've found your problem and it's in you AppDelegate. The property isTranslucent which is set to false to your navigation controller seems to cauese this rare problem. A translucent navigation bar will be on top of your viewcontroller's view, like above it. A non-translucent navigation bar pushes down your view controller's view or in other words rezising it so it fits beneath it.. But why the collectionview animates like it does is something I actually cant give a definite answer about. Maybe someone else could do that?..
To keep your navigation bar translucent you can set another property in your viewcontroller which is ´extendedLayoutIncluedsOpaqueBars´ to true.
So.. Do like this. In your AppDelegate:
window = UIWindow(frame: UIScreen.main.bounds)
window!.makeKeyAndVisible()
let controller = TestingNavigationController()
let navigation = UINavigationController(rootViewController: controller)
window!.rootViewController = navigation
let navigationBarAppereance = UINavigationBar.appearance()
navigationBarAppereance.isTranslucent = false
Then, in your view controllers viewDidLoad method add this line
extendedLayoutIncludesOpaqueBars = true
Hope this will solve your problem! :)
Apple Documentation about extendedLayoutIncludesOpaqueBars

Related

How to prevent view goes under UITabBar when using code to layout

I added UIViewController which has no storyboard to UITabBar.
It seems the view of added VC goes under the tab bar which does not
happen when I add a vc which used Storybaord to UITabBar.
How can I prevent this?
If you don't want the viewcontroller extend to any edges, you can try:
viewController.edgesForExtendedLayout = []
or viewController.extendedLayoutIncludesOpaqueBars = false should also work

UIColletionView Jumps Up On Popping Back From Another Controller

i have a uicollectionviewcontroller as rootviewcontroller in my navigationController. whenever i return from another controller that is pushed onto this stack. the collectionview jumps up 25pix. i have tried some tips from other questions like self.automaticallyAdjustsScrollViewInsets = false, changing contentOffset after collection appears but none of them work.
i have no idea what causes this problem.
this is a sample off whats happening
This property is applied only to view controllers that are embedded in a container such as UINavigationController
The window’s root view controller does not react to this property. The default value of this property is UIRectEdge.all
Setting it to UIRectEdge.none should resolve it
self.edgesForExtendedLayout = UIRectEdge.None
Seems that you have this problem because of tabbar.ishidden = true and then after pop the view controller you will again set the tabbar.ishidden = false .
this would fix with a review in your constraint in storyboard, e.g if you have your bottom constraint to tabbar, change it to superView. this would prevent relayouting your collecitonView.

Set a view above navigation controller and below popupView

I have a collection View with navigation bar on StoryBoard. There is a popupView that appears when custom cell is selected.
On main StoryBoard I set a View dimView to make dark background color while pop up view is showing.
However when I test on device, dimView does not go above Navigation Bar or TabBar.
I tried following code let window = UIApplication.shared.keyWindow! window.addSubview(dimView). But it makes dimView above pop up View.
I would like to set a view above navigation controller and below popupView.
Any idea how to solve this?
Have You try adding dimview on window but below popUp like this
let window = UIApplication.shared.keyWindow!
window.insertSubview(dimView, belowSubview: popupView)

Setting titleView of UINavigationItem makes titleView disappear

I've set the titleView of a UIViewController's navigationItem after init(). After pushing the VC to UINavigationController, titleView appears correctly at first time. But when I change (re-set) a titleView to an other view, it suddenly disappears.
But when I push another view controller and navigate back, it suddenly appears.
Do I have to perform any actions after re-setting the titleView?
If you are not using tab bar controller, then in viewDidLoad
setting the title as self.title is better.I have mentioned Tab bar Controller because if you have a view controller (in a NavigationController) in a UITabBarController, then if you set self.title it overrides the name of the tab as well as the top title.
I think you maybe code like this:
self.navigationItem.titleView = self.yourView;
If your yourView is a custom class , it maybe remove from superView when you switch your viewcontroller to next one;
So code like this maybe solve your problem:
[self.navigationItem.titleView addSubview:yourView];

Change Split View Controller Navigation Bar Colour

I have a split view controller and I want to change the navigation bar colour.
Using the below in app delegate I have changed the colour of the detail screen (right).
navigationController.navigationBar.barTintColor = UIColor.orangeColor()
But I can't seem to figure out how to change the bar of the navigation controller (left).
Can anyone help?
Thanks
The template provides you a MasterViewController (the left) and a DetailViewController (the right). It is the same code in both the MasterViewController and the DetailViewController, likely in viewDidLoad. You have it right, although there is an optional you are missing:
if let navContr = self.navigationController {
navContr.navigationBar.barTintColor = UIColor.orangeColor()
}

Resources