Obj-c show navbar after hideBarOnSwipe true - objective-c

Currently the navbar will hide if the user is scrolling down. But it won't display back the navbar when user is scrolling up. how to display the navbar back when the user is scrolling up?
i am using this code to hide the navbar
self.navigationController.hidesBarsOnSwipe = YES;
The navbar will display back if the user tap twice on the top screen area, but I found it won't be so user-friendly.
Have been searching for the answers for quite a while, but can't find any
clue. What am I missing??
thanks!

I suggest you try adding scrollViewScroll as below
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGPoint scrollOffset = scrollView.contentOffset;
if (scrollOffset.y >= 40)
{
if (![self.navigationController isNavigationBarHidden])
{
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
}
else
{
if ([self.navigationController isNavigationBarHidden])
{
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
}
}

I have used one Git lib for scroll table view/ Scroll top to bottom / bottom to top. It will automatically adjust the Navigation bar.
AMScrollingNavbar
you can use like this.
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[(ScrollingNavigationController *)self.navigationController followScrollView:self.tableView delay:40.0f];
}

Related

Navigation bar Hidden not working IOS

Hi I'm new in iOS development. I've one main screen with navigation bar hidden true. From there I am navigating to another view using back segue. but when I click back it showing navigation bar on main screen. Here is my problem description.
In main screen onviewload I am doing :
self.navigationController.navigationBarHidden = YES;
once user go to another view using back segue in new controller, I'm doing
self.navigationController.navigationBarHidden = NO;
And now, if I click back it will show navigation bar on main window also which I don't want. Basically I want main screen without navigation bar and next window with navigation bar.
How to do this. Need Help. Thank you.
Put that code in viewWillAppear instead of viewDidLoad, and it should work properly.
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.navigationController.navigationBarHidden = YES;
}
I have a Tab viewcontroller consist of 4 tabs, one of my tab doesn't need navigationbar, but others need.
None of the previous answers solve my case, these code does.
//隐藏App导航条,使用RN自己的导航条
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.navigationController.navigationBar.hidden = YES;
// self.navigationController.navigationBarHidden = YES; //这句是 **完全没** 个卵用
// [self.navigationController setNavigationBarHidden:YES animated:NO];
}
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:NO];
}
//恢复App导航条
- (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
self.navigationController.navigationBar.hidden = NO;
// self.navigationController.navigationBarHidden = NO; //这句是 **完全没** 个卵用
[self.navigationController setNavigationBarHidden:NO animated:NO];
}
Don't use
self.navigationController.navigationBarHidden = YES;
You should use
self.navigationController.navigationBar.hidden = NO;
For Swift 4, add following in viewWillAppear
self.navigationController?.setNavigationBarHidden(false, animated: false)
self.navigationController?.setNavigationBarHidden(false, animated: false)
Put the above line of code in viewWillAppear instead of viewDidLoad.

Transition between views as if one was modal

I've got a login screen I want to hide like:
[self dismissModalViewControllerAnimated:true];
But the problem is that I need to display it like this:
-(void)viewDidAppear:(BOOL)animated {
[self presentModalViewController:loginScreen animated:false];
}
Which means I'll flash the current screen before I popup the login screen.
So what I'm looking for is a way to show the login screen instantly and transition to the main screen with the same animation as dissmissModalViewControllerAnimated:true.
You should be able to just disable the animation so its instant?
[self presentModalViewController:loginScreen animated:NO];
Do it in viewWillAppear if it still flashes briefly.
What I've done (maybe not the best solution):
- (void)viewDidLoad
{
// Initial set to hidden for avoiding a flickering UI
self.view.hidden=YES;
}
-(void)viewWillAppear:(BOOL)animated
{
[NSTimer scheduledTimerWithTimeInterval:0 block:^{
[self presentModalViewController:self.loginViewController animated:NO];
} repeats:false];
}
And just before you dispatch the ModalViewController you set self.view.hidden=NO.
See https://github.com/jivadevoe/NSTimer-Blocks for the NSTimer using blocks

MFSideMenu full size pan gesture

I use MFSideMenu in my application, and i can show the menu using a pan gesture on the navigation bar only. I would like it to work on the whole screen, like on the facebook app.!
I've tried changing this line (l.39 in MFSideMenuManager.m)
[controller.navigationBar addGestureRecognizer:recognizer];
to this :
[controller.view addGestureRecognizer:recognizer];
but it just won't work.
Do you have any idea of what i should edit for it to work?
Thank you for your help
I finally succeeded making it work. The gesture is actually already implemented but working only if the menu is hidden. We have to remove 2 conditions to make sure it works both ways
There are two lines to edit in the MFSideMenuManager.m
In the gestureRecognizerShouldBegin: method
if([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
if([gestureRecognizer.view isEqual:self.navigationController.view] &&
self.navigationController.menuState != MFSideMenuStateHidden) return YES;
becomes
if([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
if([gestureRecognizer.view isEqual:self.navigationController.view]) return YES;
In the navigationControllerPanned: method, just remove the if line
- (void) navigationControllerPanned:(id)sender {
if(self.navigationController.menuState == MFSideMenuStateHidden) return;
[self handleNavigationBarPan:sender];
}
becomes
- (void) navigationControllerPanned:(id)sender {
[self handleNavigationBarPan:sender];
}
And it works!
It is not a really good practice to edit a library, but it is easy if you want to go further to add a boolean option to MFSideMenu to make it configurable.
I don't know the MFSideMenuManager but if the bar is draggable I expect it to have a UIPanGestureRecognizer with a line
[self.navigationController.navigationBar addGestureRecognizer:gestureRecognizer];
So what you do is replace the navigation bar with the view for the whole navigation controller
[self.navigationController.view addGestureRecognizer:gestureRecognizer];

UIPopover is repositioned but in the wrong place

I have this code to reposition my popover:
- (void)repositionPopOver {
if (self.targetButton) {
[self.popoverController presentPopoverFromRect:self.targetButton.frame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
}
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
// Reposition the Popover after rotation
[self repositionPopOver];
}
So now when I rotate the device it does re-position my popover but in the wrong spot:
(source: minus.com)
Please note that the red rectangle is the targetButton
while rotation ,You can try dismissing popOver first and then recreate it and show it based on the orientation.
{
if([YourPopUpViewControllerOBject].isPopOverVisible)
{
[[YourPopUpViewControllerOBject] dismissPopoverAnimated:YES];
}
//Code to show PopOver based on orientation
}

UIScrollView shifts below navigation and status bar

I have view which contains a scrollView. When the view shows up the image appears in full screen (320x480) hiding the status and navigation bar. When I tap the screens - status and navigation bar appears on the screen. But this thing shifts the UIScrollView below the the navigation bar. I want the status and nav bar to show over my scroll view.
Like it happens in the photos app. On tapping the image the status and nav bar shows over the scrollView.
Below is how I am positioning the view
//What I have done in viewDidLoad
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];
self.wantsFullScreenLayout = YES;
scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
self.view = scrollView;
Below is what I am doing on detecting a single tap
- (void)tapDetectingImageView:(TapDetectingImageView *)view gotSingleTapAtPoint:(CGPoint)tapPoint {
// single tap hide/unhide the status and nav bar
NSLog(#"got a single tap");
if (self.navigationController.navigationBarHidden == NO)
{
[self.navigationController setNavigationBarHidden:YES animated:NO];
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
}
else
{
[[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES];
[self.navigationController setNavigationBarHidden:NO animated:NO];
}
}
Just a pointer for you guys -
If I use [self.view addSubview:scrollView]; I dont see this issue. But this mess up my landscape orientation code.
Anyone who can shed some light what I might be doing wrong - would be great help!
There appears to be some special handling inside UIScrollView when the navigation toolbars are toggled. As you pointed out at the end of your question, if you put the scroll view inside a containing UIView, this repositioning problem does not occur.
To fix the landscape issues, make sure you're setting the autoresizingMask on both the container view and the scroll view. I did not have to add any additional handling for landscape mode in my project.
I found the solution myself.
In my tap detecting code's else fn I add the below line in the last.
scrollView.contentOffset = CGPointMake(parentScrollView.contentOffset.x,0);
Not sure if this is the right approach. But if anyone can suggest a better approach - more than welcome!