IOS 觸摸事件--1

//觸摸開始

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

{

    NSLog(@"touchesBegan");

    

}


//移動

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

{

    UITouch *touch=[touches anyObject];

    CGPoint current=[touch locationInView:self];

    CGPoint pre=[touch previousLocationInView:self];

    CGFloat offsetX=current.x-pre.x;

    CGFloat offsetY=current.y-pre.y;

    CGPoint center=self.center;

    center.x=center.x+offsetX;

    center.y=center.y+offsetY;

    self.center=center;

}


//結束

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

{

    NSLog(@"touchesEnded");

}


//觸摸被打斷

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

{

    NSLog(@"touchesCancelled");

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章