碰撞计算,NSTimeInterval的使用, touchesEnded, touchesBegin

//注意此处坐标从数组提取**********
CGRect tappingArea=[[tapArea_Paigu objectAtIndex:i] CGRectValue];


//CGRectIntersectsRect bool型函数 判断 tappingArea是否在touchArea内。。
CGRectIntersectsRect(touchArea,tappingArea);

  

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];  
    NSLog(@"touch 1:%f", touch.timestamp);  
    m_pointBegin = [touch locationInView:self.view];  //热点位置
    m_timeBegin = touch.timestamp;  //触发时间
    
    NSLog(@"locationInView:%@", NSStringFromCGPoint([touch locationInView:self.view]));
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    NSLog(@"touch 2:%f", touch.timestamp);
    
    NSLog(@"locationInView 2:%@", NSStringFromCGPoint([touch previousLocationInView:self.view]));
    
    NSLog(@"locationInView 3:%@", NSStringFromCGPoint([touch locationInView:self.view]));
    CGPoint pointEnd = [touch locationInView:self.view];
    
    //judge if touch is enable
    if (m_pointBegin.y <= 320)
    {
      //勾股定理,计算类似(x3,y3和x5,y4) CGFloat kDistance = sqrt((pointEnd.x - m_pointBegin.x)*(pointEnd.x - m_pointBegin.x) + (pointEnd.y - m_pointBegin.y)*(pointEnd.y - m_pointBegin.y)); if (kDistance <= 10) { //judge if time is validate NSTimeInterval endTime = touch.timestamp; NSTimeInterval timeInterval = endTime - m_timeBegin; NSLog(@"timeInterval:%f", timeInterval); if (timeInterval >= 0.5) { if(m_bIsEnableAlarmAction) { NSLog(@"longPressStatus"); [CommonReq AllAlarmTime]; m_bIsReqReadTemperature = YES; if(m_viewScenarWait.superview != nil) { [self removeScenarioWaitView]; } [self createScenarioWaitView]; [self showScenarioWaitView]; if ([m_timerScenarioInfo isValid]) { [m_timerScenarioInfo invalidate]; m_timerScenarioInfo = nil; m_nTimeout = 0; } [self removeScenarioView]; self.m_timerScenarioInfo = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(requestTimeout) userInfo:nil repeats:YES]; [ABUtil addTimeToCurrentRunLoop:m_timerScenarioInfo]; } } } } }

  

posted @ 2013-11-27 17:32  暖流  阅读(407)  评论(0编辑  收藏  举报