![](/img/trans.png)
[英]iOS: Detect if touchEnded comes from sliding off screen or lifting finger?
[英]Making multiple objects on screen detect a finger sliding?
我的目標是在屏幕上獲得一堆正方形以檢測滑動的手指,並且只有當其前面的正方形滑過時,它們才會執行其功能。 我想知道是否有人有什么好的建議或想法可以使用? 我當時在想創建一個NSMutableArray
,使用一個結構包含每個正方形的點,然后將該結構包裝在NSValue
然后將其添加到數組中。 然后,我想我將使用循環讀取數組並在屏幕上創建所有正方形。 但是,當手指在正方形上滑動時,如何使正方形檢測呢? 我是否需要在循環中進行設置? 有沒有人有什么建議? 抱歉,我是iOS游戲開發者的新手。 世界!
您的問題讓我有些困惑,但是我想尋找的是以下內容:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
CGPoint touchLocation = [touch locationInView:self.contentView];
for (UIView *view in self.contentView.subviews)
{
if ([view isKindOfClass:[MyCustomView class]] &&
CGRectContainsPoint(view.frame, touchLocation))
{
}
}
}
這將在屏幕上的對象之一被觸摸時檢測到。 如果這不能解決您的問題,請告訴我,我將嘗試進行修改以更好地解決該問題
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.