[英]How can I pass a gesture recognizer from one view to another
我有一個視圖,其中包含幾個子視圖,這些子視圖是具有多個按鈕的復雜控件 superview具有用於水龍頭,滑動等的手勢識別器。
在某些情況下,當接收單次或雙次觸摸時,我希望超級視圖將手勢識別器傳遞給子視圖以進行治療。
例如:
singletaprecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onSingleTapGestureRecognizerDetected:)];
- (void)onSingleTapGestureRecognizerDetected:(UITapGestureRecognizer*)theTapGestureRecognizer
{
if (someCaseHappens) {
// do something with the gesture - for instance - move a control from one place to another or some other UI action in the superview
}
else {
// the subview will need to get the gesture and do something with it (imagine the touch was inside a button in a subview - the top superview should disregard the gesture and the button should be pressed) - THIS ISN"T HAPPENING NOW
}
}
好吧,您可以創建一個繼承自UIView
的自定義視圖,然后覆蓋:
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
通過此方法,您可以返回要處理事件的視圖。
請查看: https : //developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/instm/UIView/hitTest : withEvent :
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.