I found a strange thing. Following is just a simple demo project.
In TestViewController.m:
In AppDelegate:
When I set the translucent of the navigationBar to NO, the UIButton in the displayed viewController will not show. Conversely, if I do not set, the button will appear.
Could anyone explain it to me? I believe it is a bug of Apple.
"set the translucent of the navigationBar to NO" will make the height of UIViewController's view reduce 44 point(navigationBar's height) which make your button invisible.
Your button's frame is out of the view's bound. Adjust your uibutton's frame according to the bound of viewController's view.
Related
I want to place image over navigation bar, but partially on it an partially on content view. So I set UINavigationBar.layer.zPostion to -1 and it works perfectly well especially on iPhones. But I also have background UIImageView with UIImage and it should be placed beneath navigation bar. So I tried to set it zPosition to -2 or -10 it doesn't work and it is seen through navigation bar somehow. I even tried to place another UIView above Background UIImageView and beneath NavigationBar to be able to mask/hide this image and have colour like navigation bar. But it doesn't work. If i use UIView with some color instead of ImageView then it works correctly.
I've forgotten to add
clipToBounds = true
This solves the problem
I want to position the UINavigationBar x pixels from the top. Is this possible? Here is a screenshot of the desired result.
To clarify, I want the NavigationBar to be positioned in the orange area. The area black area above is an ARKit view running and should not be covered by anything.
Is this even possible?
I've tried setting the NavigationBar frame and messing around with the positionForBar property. Nothing have an effect, the NavigationBar is always rendered at the top. One thing that add is that this solution, if there is any, has to be done in code and not in storyboard.
Just create a constraint from the Top Safe Area Guide's bottom to your view...?
Unfortunately, You have said it, you changed the frame but nothing happened as you don't have the ability to change(Move or resize) the UINavigationController's navigation bar. To solve this problem you have to write your own view controller class.
Try setting the navigation bar’s transform.
i.e.
navigationController?.navigationBar.transform = CGAffineTransform(translationX: 0, y: yourTopInset)
I have a custom view (not UIButton) for navigationItem.titleView and I did a little trick to make it be fullwidth by overriding setFrame method so that it doesn't get resized automatically by the navigation controller to be shrinked ( to achieve what i want - fullwidth) I set the titleView at the viewDidLoad event.. the problem is that while the transition the navigation bar do some kind of repositioning and I see my view blinking at the transition and getting a little bit down and then blinking back to its position.. It's really irritating problem , any idea where this is coming from ?
Updated -Not solved yet-
my custom view is not a UIButton to be solved like this (thanks to #Sneak)
ios - navigationItem.titleView blinks when updated
Have you tried setting the autoResizingMask of your custom tileView to UIViewAutoresizingFlexibleTopMargin?
In my case self.view.layoutSubviews() caused the issue. According to the official documentation, I used setNeedsLayout() instead, so the blinking has gone! (The constraint animation too, but this is another story.) Note: layoutIfNeeded() causes blinking for custom navigation as well.
When I switch navigationBar to translucent, my UISearchDisplayController went crazy.
The dimmed area is missplaced by 64px, same for first row in results table.
I know how to fix resultTableView missplacement, but I cannot find a way to fix dimmed area frame.
Strangely enough I found that my main view is in origin.y = 64.0f when translucent is set to YES.
It happens somewhere in between viewDidLoad, viewDidAppear. If I change it it works, but than transitions between views in navigations controller are broken.
=============
Problem solved by: extendedLayoutIncludesOpaqueBars
Check the search bar's AutoLayout/AutoResizingMask settings.
Also make sure you're not manually modifying the bar's frame as the system will try to animate the bar into its position along the dimmed view and results' table view.
When you set the translucent property and automaticallyAdjustsScrollViewInsets to YES (default): a) the view gets stretched under the navigation bar and b) a top contentInset is added to the underlying UIScrollView (table view is a subclass).
My guess is that only b) is happening in your case for some reason. You can try to solve it by either:
Clear automaticallyAdjustsScrollViewInsets.
Removing the automatically added contentInset from your scroll view.
Setting your controller to do a) even with opaque bars by setting extendedLayoutIncludesOpaqueBars.
I have a custom UITabBarController and using setFrame in the viewDidLoad I move the tabBar to the top of the screen. This works fine.
In Interface Builder I have pushed down the elements (buttons, labels, etc) in the XIB file of the so that there is room for the tabBar at the top. I have made sure to set the Bottom Bar to none (in the simulated metrics of the inspector) and made sure that the UIView is 480 in height.
When I test this however the tabBar is at the top as expected, but the view is clipped off where the tab bar would normally be. Even the background UIImage does not show through. It is just white. How can I increase the frame size of the viewController?
I tried changing adding a setFrame command to [self view] in the viewDidLoad of the subview, but that did not do the trick.
Thanks
UITabBarController automatically sets the frame for active view controllers.
You can try to modify the view's frame afterwards or try setting clipSubviews = NO for all views.
Maybe you want to try to execute the following in viewDidAppear: or some other place (try!). This will hopefully change back the frame of the view after the tab bar controller modified it.
dispatch_async(dispatch_get_main_queue(), ^(void){
[self.view setFrame:CGRectMake(0,0,320,480);
});