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

UIView 화면 터치시 single tap , double tap에 대한 구현

by 백룡화검 2011. 6. 2.

아이폰 개발시 화면 터치에 대한 single tap , double tap에 대해서 구현해보자 




물론 UIView를 상속 받아야지만 아래의 터치 관련 함수가 콜된다~

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

{

 NSUInteger tapCount = [touch tapCount];

    

    switch (tapCount) {

        case 1:

            [self performSelector:@selector(singleTapMethod:) withObject:nil afterDelay:.4];

            break;

        case 2:

            [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(singleTapMethod:) object:nil];

            [self performSelector:@selector(doubleTapMethod:) withObject:nil afterDelay:.4];

            break;

        case 3:

            [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(doubleTapMethod:) object:nil];

            [self performSelector:@selector(tripleTapMethod:) withObject:nil afterDelay:.4];

            break;

        case 4:

            [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(tripleTapMethod:) object:nil];

            //[self quadrupleTap];

            break;

        default:

            break;

    }
 }


-(void)singleTapMethod:(id)sendef

{

    //NSLog(@"singleTapMethod");

}


-(void)doubleTapMethod:(id)sendef

{

    

    //NSLog(@"doubleTapMethod");

}



-(void)tripleTapMethod:(id)sendef

{

    

   // NSLog(@"tripleTapMethod");




출처 : http://iphonedevelopment.blogspot.com/2008/10/handling-double-taps.html





출처 : http://dongss.tistory.com/entry/iOS-%EC%95%84%EC%9D%B4%ED%8F%B0-%EA%B0%9C%EB%B0%9C-UIView-%ED%99%94%EB%A9%B4-%ED%84%B0%EC%B9%98%EC%8B%9C-single-tap-double-tap%EC%97%90-%EB%8C%80%ED%95%9C-%EA%B5%AC%ED%98%84