SingleTouch 和 MutliTouch

来源:互联网 发布:mysql创建存储过程例子 编辑:程序博客网 时间:2024/05/29 14:41

不论SingleTouch 还是 MutliTouch

self.view.userInteractionEnabled = YES;  //交互首先要赋值为YES

SingleTouch

//touch开始时调用这个方法

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

}

//touch移动时调用这个方法

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

}

//touch结束时调用这个方法

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

}

//touch取消时调用这个方法

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event

{


}

MutliTouch比如:2点touch


         self.view.userInteractionEnabled = YES;   //用户交互打开,这样touch才会有反应
         self.view.multipleTouchEnabled = YES;   //多点touch打开,不然只能识别Singletouch

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    
    if ([touches count]==2) { 

      //获取2个touch点

       NSArray *array_touches = [touches allObjects];
    
       UITouch *touch1 = (UITouch *)array_touches[0];
       UITouch *touch2 = (UITouch *)array_touches[1];     

        //利用touch点做一些事情

        self.xLabel.center = [touch1 locationInView:self.view];
        
        self.yLabel.center = [touch2 locationInView:self.view];



      }

}


- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
   if ([touches count]==2) {
      //获取2个touch点

        NSArray *array_touches = [touches allObjects];
    
       UITouch *touch1 = (UITouch *)array_touches[0];
       UITouch *touch2 = (UITouch *)array_touches[1];    


   }
}


- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{  if ([touches count]==2) {
    //代码
  }
}





0 0
原创粉丝点击