我相信这是可能的。
如果你想要一些简单的用户交互,比如向下拖动,那么你需要使用UIScrollView 并实现它的委托。之后,您可以使用其中一些方法
– scrollViewWillEndDragging:withVelocity:targetContentOffset:
– scrollViewDidEndDragging:willDecelerate:
然后只需显示/隐藏 UINavigationBar 之后
[self.navigationController setNavigationBarHidden:YES/NO animated:YES];
如果上面的逻辑不起作用。你可以用UIView 伪造UINavigationBar。使用这些委托很容易显示和隐藏它。
//编辑:如果你不想使用UIScrollView,你可以使用UIPanGestureRecognizer并检查手势是否是向下/向上拖动。不过,我认为使用UIScrollView 会容易得多。
//更新:
您仍然可以使用UIScrollView 和UIWebView。像这样
-(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];
}
完成! :)