2012-06-19 95 views
1

在我的應用程序中,我有一個主屏幕,它有一個子視圖(這是另一個屏幕),但是此子視圖向右移動320,因此它只是在屏幕外。效果是主屏幕向左移動320,隱藏主屏幕並顯示其他屏幕,因爲它是子視圖。問題是,另一個屏幕沒有接收觸摸事件,因爲它超出了主屏幕(超級視圖)的範圍。我如何獲得這個其他屏幕也可以接收觸摸事件,所以我可以點擊按鈕?主視圖外部的子視圖不會接收觸摸事件

回答

0

看一看this post on S.O.的解釋。解決方案是使用以下代碼實現您自己的hitTest:

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event { 

    BOOL isInside = [super pointInside:point withEvent:event]; 

    // identify the button view subclass 
    UIButton *b = (UIButton *)[self viewWithTag:3232]; 
    CGPoint inButtonSpace = [self convertPoint:point toView:b]; 

    BOOL isInsideButton = [b pointInside:inButtonSpace withEvent:nil]; 

    if (YES == isInsideButton) { 

     return isInsideButton; 

    } // if (YES == isInsideButton) 

    return isInside; 
} 

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { 

    UIView *v = nil; 

    v = [super hitTest:point withEvent:event]; 

    return v; 
} 
相關問題