我认为我想拥有全屏,我正在隐藏系统栏和UINavigationBar
,但我想让它重新出现在某些用户互动上,例如拖动内容或按下顶边等(这更容易实现,更友好)。
到目前为止,我的搜索没有成功,因此我对SO的问题。
编辑: 值得一提的是,这个全屏显示的视图是UIWebView,UINavigationBar用于此视图,通过后退按钮提供“返回”功能。
答案 0 :(得分:2)
我相信它是可能的。
如果您想要一些简单的用户交互,例如向下拖动,那么您需要使用UIScrollView
并实现其委托。之后,您可以使用其中一些方法
– scrollViewWillEndDragging:withVelocity:targetContentOffset:
– scrollViewDidEndDragging:willDecelerate:
然后只显示/隐藏UINavigationBar
[self.navigationController setNavigationBarHidden:YES/NO animated:YES];
如果上述逻辑不起作用。您可以使用UINavigationBar
伪造UIView
。这些代表很容易展示和隐藏它。
//编辑:如果您不想使用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];
}
完成! :)