2012-06-22 24 views
0

我有一個UIView,我正在渲染基於touchesBegan和touchesMoved的UIBezierPath。但我只想在UIVIEW內的某個區域畫畫。我想在UIView中設置一個只有註冊觸摸的CGRect。此區域以外的任何觸摸都不會被註冊。UIView只接受某些區域的觸摸

理想情況下,如果用戶在這個矩形之外刨削,他們可以保持觸摸,但touchesBegan方法將在他們拖回區域時被調用。

任何人都可以幫忙嗎?謝謝。

回答

1

使用pointInside:withEvent:告訴它不接受該點,如果它在區域之外。

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event{ 
    return [self isPointWithinMyBounds:point]; 
} 

- (BOOL) isPointWithinMyBounds:(CGPoint) point{ 
    //determine if the point is within the rect 
    return NO; 
} 

touchesMoved事件將是複雜的事件。你會在視圖外面停止繪圖。

但這應該達到您想要的效果。

0

您可以將隱形UIView放在當前的UIView上,並根據您的預期觸摸區域進行調整。然後只將手勢識別器添加到該視圖。