Scrolling UINavigationBar similar to Mobile Safari

It is used in my application UINavigationController, and the final view (detailed view) allows me to view an external website in the application using UIWebView.

I would like to free up additional screen real estate when a user views a web page, and would like to imitate how Safari works on the iPhone, where their URL bar at the top views and turns off the screen when viewing content in UIWebViewthat below the fold.

Anyone have any ideas on how to achieve this? If I set a property navigationBarHiddenand collapse my own panel at the top and set it UIWebViewwithin UIScrollView, then there UIWebVieware problems with scrolling, since it does not play well with other scrollable views.

+3
source share
3 answers

Based on @Brian's suggestion, I made this code:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    CGFloat height = navigationBar.frame.size.height;
    CGFloat y = scrollView.bounds.origin.y;
    if (y <= 0) {
        CGRect frame = navigationBar.frame;
        frame.origin.y = 0;
        navigationBar.frame = frame;
    } else if (tableView.contentSize.height > tableView.frame.size.height) {
        CGFloat diff = height - y;
        CGRect frame = navigationBar.frame;
        frame.origin.y = -y;
        navigationBar.frame = frame;

        CGFloat origin = 0;
        CGFloat h = height; // height of the tableHeaderView
        if (diff > 0) {
            origin = diff;
            h = y;
        }
        frame = tableView.frame;
        frame.origin.y = origin;
        frame.size.height = tableView.superview.frame.size.height - origin;
        tableView.frame = frame;

        CGRect f = CGRectMake(0, 0, tableView.frame.size.width, h);
        UILabel* label = [[UILabel alloc] initWithFrame:f];
        tableView.tableHeaderView = label;
        [label release];
    }
}

UITableView, . , navigationBar UIScrollView, . - :

frame.size.height = tableView.superview.frame.size.height - origin - otherComponentsHeight;

tableHeaderView, . , , scrollViewDidScroll: , , Mobile Safari , , . contentOffset.y 0, , , , . tableHeaderView, , , , , , navigationBar .

t ableHeaderView, navigationBar.

enter image description here

tableHeaderView ( scrollbar), tableHeaderView, , offset, , navigationBar :

enter image description here

+4

UIWebView UIWebView, UIWebView Y- , Y. , , UIWebView .

, UIWebView .

, , UIWebView.

+1

I can not give you a direct answer, but look at iWebKit. Perhaps this is a solution. The demo at least contains the Full Screen element.

0
source

Source: https://habr.com/ru/post/1714926/


All Articles