Thứ Năm, 30 tháng 9, 2010

How to handle long tap even

This is my simple method to do this on touch began u have to get the point and store it as first and second that should be equal for future compare and then start timer, when the timer ends u have to compare first and second, if it equals then its long press!

And if the touches ends or moved u have to break timer as well as store the point as second point!!

some more detailed
Code:

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

UITouch *touch = [touches anyObject];
firstPoint=secondPoint = [touch locationInView:self];
//start timer
}

-(void)onTimerCall{

//check first and second point for equals if it equals its long tap

}

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

UITouch *touch = [touches anyObject];
secondPoint = [touch locationInView:self];

}

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

UITouch *touch = [touches anyObject];
secondPoint = [touch locationInView:self];
}

Không có nhận xét nào:

Đăng nhận xét