wgp*_*ubs 7 objective-c uiscrollview uiview touch-event ios
我有一个UIView
包含a UIScrollView
,我希望能够UIView
在用户点击的任何时候捕获"Touch Down"事件UIScrollView
.
我已经尝试将所有touchesBegan/Ended/Cancelled处理程序包含在我的中,UIViewController
但是当点击UIScrollView
main中包含的内容时,它们都没有被触发UIView
.
完成此任务的最佳方法是什么?
在UIView中,实现touchesBegan:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
// assign a UITouch object to the current touch
UITouch *touch = [[event allTouches] anyObject];
// if the view in which the touch is found is myScrollView
// (assuming myScrollView is the UIScrollView and is a subview of the UIView)
if ([touch view] == myScrollView) {
// do stuff here
}
}
Run Code Online (Sandbox Code Playgroud)
旁注:确保 UIView 中的 userInteractionEnabled 设置为 YES。
归档时间: |
|
查看次数: |
8677 次 |
最近记录: |