开发者

UISwipeGestureRecognizer gesture start point

开发者 https://www.devze.com 2023-01-18 18:06 出处:网络
Is it possible to get a gesture start point from a UISwi开发者_Python百科peGestureRecognizer. like how its possible in

Is it possible to get a gesture start point from a UISwi开发者_Python百科peGestureRecognizer. like how its possible in

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

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


According to the UISwipeGestureRecognizer documentation you can:

You may determine the location where a swipe began by calling the UIGestureRecognizer methods locationInView: and locationOfTouch:inView:. The former method gives you the centroid if more than one touch was involved in the gesture; the latter gives the location of a particular touch.

PS: you really should first look at the documentation, the answer was in the class reference of UISwipeGestureRecognizer, shouldn't be hard to find. Part of being a developer is being able to look things up, Apple has excellent documentation, use it!


WARNING

Amy's answer is totally INCORRECT! Recognizer may generate UIGestureRecognizerStateBegan but on swipe UISwipeGestureRecognizer generates UIGestureRecognizerStateEnded event only.

But touchesBegan: works instead. The problem is if it supports user interaction then it works for current view only and you need to pass it to a parent view.


Yes, it is possible. See code below:

if ([recognizer state] == UIGestureRecognizerStateBegan || [recognizer state] != UIGestureRecognizerStateChanged) {
    NSLog(@"StateBegan :::::");
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号