leo*_*ato 8 iphone cocoa-touch
我是iPhone开发的新手,并没有做任何有趣的事情.我的视图层次结构如下:
Run Code Online (Sandbox Code Playgroud)UIView - UIImageView - UIScrollView - CustomView
如何检测用户是否点击了屏幕上的任何位置,以便我可以相应地显示/隐藏导航栏?我不需要在我的CustomView上进行用户交互,但是当用户只想拖动它时,我想忽略UIScrollView上的触摸.
我已经可以使用以下命令以编程方式显示/隐藏我的视图控制器中的导航栏:
[self.navigationController setNavigationBarHidden:YES animated:YES];
Run Code Online (Sandbox Code Playgroud)
提前致谢!
Mug*_*nth 16
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showHideNavbar:)];
[self.view addGestureRecognizer:tapGesture];
[tapGesture release];
-(void) showHideNavbar:(id) sender { // write code to show/hide nav bar here }
Run Code Online (Sandbox Code Playgroud)
这是使用iOS4上提供的UIGestureRecognizers进行此操作的方法
您可以使用UIView中的touchesBegan方法来检测tap,因此您必须UIView为viewcontroller的视图设置一个自定义子类,以便检测您的点击.然后你将不得不使用委托给视图的控制器发消息,这样它就可以隐藏了navigationBar.
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSUInteger numTaps = [[touches anyObject] tapCount];
if (numTaps == 1)
{
[delegateController tapDidOccur];
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9440 次 |
| 最近记录: |