문제

I'm developing an app for iOS, and I want the user to be able to select some stuff on the screen, and then at the end of the selection be able to hold the finger for a second, to trigger some other event.

I have already created a lot of actions, for when the user marks stuff by swiping around. For this i have been using:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    //Stuff here
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    //Stuff here
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    //Stuff here
}

I don't care if these functions are used, or if it done by UIGestureRecognizer, but i simply can't find a efficient and simple way to implement this.

Any suggestions?

도움이 되었습니까?

해결책

You could initiate a NSTimer when a touch began, if the finger is within a target area, and if the touch ended function is called before the timer has fired r some condition is met within the touch moved function then cancel the timer, otherwise let it fire.

다른 팁

You'll probably need to use a timer as well as a pan gesture recognizer. When the finger reaches a target area, start the timer. If the finger moves out of the area, invalidate the timer. If the timer fires, it's a long press.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top