[英]How do I detect a touch over a specific area
目前我看到觸摸事件將向我顯示觸摸發生的UIView。 但是,如果我需要檢測一些非矩形形狀的觸摸,如圓形。 我該怎么做呢?
基本上我只想在用戶觸摸不可見的圓形區域內的某個地方時才做某事。
任何幫助/方向表示贊賞,TIA!
你會這樣做的。 請注意,'locationInView'將返回相對於指定視圖的觸摸坐標,因此無論視圖在屏幕上的哪個位置,視圖左上角的觸摸都將返回(0,0)。
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
// gets the coordinats of the touch with respect to the specified view.
CGPoint touchPoint = [touch locationInView:self];
// test the coordinates however you wish,
...
}
要測試球體,您將計算從觸摸點到球體中心的距離,然后檢查這是否小於球體半徑。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.