faw*_*waz 1 objective-c uiview ios
我有一个scrollview.在scrollview中,我有三个子视图,A,B,C.当我点击子视图A时,我想获得其标记值或知道我点击了哪个视图.我已经浏览了很多代码和博客,但找不到解决方案.
- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer {}
- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event{} //This function is not working with sub view.
Run Code Online (Sandbox Code Playgroud)
试过这些方法,但没有解决我的问题.
使用UITapGestureRecognizer.为A,B,C视图中的每一个添加一个点击手势识别器,将该委托设置为视图控制器,每次点击都会通知您.
UITapGestureRecognizer* tgrA = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
[viewA addGestureRecognizer:tgrA];
...
-(void) handleTapGesture:(UIGestureRecognizer *)sender
{
//sender.view.tag will give you what you need.
}
Run Code Online (Sandbox Code Playgroud)
有关点击手势识别器的更多信息,请访问:https: //developer.apple.com/library/ios/documentation/uikit/reference/UITapGestureRecognizer_Class/Reference/Reference.html
| 归档时间: |
|
| 查看次数: |
374 次 |
| 最近记录: |