Question

I have a view that I want to have full screen, I'm hiding system bar and UINavigationBar but I would like to have it re-appear on some user interaction e.g. drag content down or press near top edge etc. (which ever is easier to implement and more user friendly).

I've searched with no success so far thus my question on SO.

EDIT: Worth to mention is that this view that is displayed full screen is UIWebView and UINavigationBar is used on this view to give "go back" ability with back button.

Was it helpful?

Solution

I belive it's possible.

If you want some simple user interactions like drag down, then you need to use UIScrollView and implement its delegate. After that, you can use some of these methods

– scrollViewWillEndDragging:withVelocity:targetContentOffset:

– scrollViewDidEndDragging:willDecelerate:

Then just show/hide the UINavigationBar afterward

[self.navigationController setNavigationBarHidden:YES/NO animated:YES];


If the logic above does not work. You can fake the UINavigationBar with an UIView. It's easy to show and hide it with these delegate.

//Edit: if you don't want to use UIScrollView, you can use UIPanGestureRecognizer and check if the gesture is a drag down/up or not. However, I think using UIScrollView will be much easier.


//Update: You can still use UIScrollView and UIWebView. Like this

-(void)viewDidLoad
{
    //init an UIScrollView and UIWebView
    [self.view addSubview:theScrollView];
    [theScrollView addSubview:theWebView]; 

    //back button
    UIButton *back = [[UIButton alloc] init];
    //custom button: set its frame, title, image ...

    //set action for button
    [back addTarget:self action:@selector(backAction:) forEvent:UIControlEventTouchUpInside];
    //add to view
    [theWebView addSubView: back]; //or [self.view addSubView:back]; --both will work just fine

}

-(void)backAction:(UIButton *)sender
{
    //if you use navigation push, use this
    [self.navigationController popViewControllerAnimated:YES];
    //if you use navigation modal, add this line of code to its previous view controller
    [self.navigationController dismissViewControllerAnimated: YES completion: nil];
}

Done ! :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top