본문 바로가기
프로그래밍/iOS

[snippet] Touch Method

by 백룡화검 2012. 7. 22.
출처 : http://cafe.naver.com/mcbugi/222780

이것도 별껀 아닌데.. 그냥 올려둡니다.
교재에 나와있는건데.. 쓸때마다 귀찮더라구여..
걍 스니펫 넣어서 돌리고 있습니다.

메소드 내부에 로그들은 따로 안건드렸습니다.
걍 두면 로그 찍어줍니다.

필요한 부분있으면 쓰면될듯하고..


#pragma mark - Touch Began, Moved, Ended
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    
    NSUInteger touchCount = [touches count];
    NSUInteger tapCount = [[touches anyObjecttapCount];
    NSLog(@"Touches Began");
    NSLog(@"%@",[NSString stringWithFormat:@"%d touches", touchCount]);
    NSLog(@"%@",[NSString stringWithFormat:@"%d taps", tapCount]);
    
    // display touch point
    UITouch *touch = [touches anyObject];
    CGPoint point = [touch locationInView:self.view];
    CGFloat pointx = point.x;
    CGFloat pointy = point.y;
    NSLog(@"%@",[NSString stringWithFormat:@"X = %.2f",pointx]);
    NSLog(@"%@",[NSString stringWithFormat:@"Y = %.2f",pointy]);
    
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    
    NSUInteger touchCount = [touches count];
    NSUInteger tapCount = [[touches anyObjecttapCount];
    NSLog(@"Touches Moved");
    NSLog(@"%@",[NSString stringWithFormat:@"%d touches", touchCount]);
    NSLog(@"%@",[NSString stringWithFormat:@"%d taps", tapCount]);
    
    // display touch point
    UITouch *touch = [touches anyObject];
    CGPoint point = [touch locationInView:self.view];
    CGFloat pointx = point.x;
    CGFloat pointy = point.y;
    NSLog(@"%@",[NSString stringWithFormat:@"X = %.2f",pointx]);
    NSLog(@"%@",[NSString stringWithFormat:@"Y = %.2f",pointy]);
    
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    
    NSUInteger touchCount = [touches count];
    NSUInteger tapCount = [[touches anyObjecttapCount];
    NSLog(@"Touches Ended");
    NSLog(@"%@",[NSString stringWithFormat:@"%d touches", touchCount]);
    NSLog(@"%@",[NSString stringWithFormat:@"%d taps", tapCount]);
    
    // display touch point
    UITouch *touch = [touches anyObject];
    CGPoint point = [touch locationInView:self.view];
    CGFloat pointx = point.x;
    CGFloat pointy = point.y;
    NSLog(@"%@",[NSString stringWithFormat:@"X = %.2f",pointx]);
    NSLog(@"%@",[NSString stringWithFormat:@"Y = %.2f",pointy]);
    
}