-4
- (void)ccTouchesBegan ...對ios觸摸代碼感到困惑
UITouch * touch = [touches anyObject];
CGPoint location = [touch locationInView:[touch view]];
有人可以請詳細解釋這兩行代碼究竟發生了什麼。 感謝
- (void)ccTouchesBegan ...對ios觸摸代碼感到困惑
UITouch * touch = [touches anyObject];
CGPoint location = [touch locationInView:[touch view]];
有人可以請詳細解釋這兩行代碼究竟發生了什麼。 感謝
UITouch *touch = [touches anyObject];
touches
是UITouch
一個NSSet
。代碼只需從touches
中獲取一個對象,並將其分配給名爲touch
的變量。這隱含地假定只包含一個元素。
CGPoint location = [touch locationInView:[touch view]];
上面的代碼行獲取觸摸在截獲觸摸的視圖的座標系中的(x,y)座標。 CGPoint
只不過是一個帶有兩個浮點值的C結構,x
和y
。
因此,底線將獲得視圖中觸摸的座標。
你有沒有花時間閱讀文檔,看看它是如何描述的? – 2013-04-06 19:43:29
對不起,我意識到我應該問更多的細節,這就是爲什麼我問這個問題 – user2252901 2013-04-06 19:48:53