简体   繁体   English

UISwipeGestureRecognizer从特定位置

[英]UISwipeGestureRecognizer from specific location

so I have a button and TouchUpInside event already assigned to that button. 所以我有一个按钮,并且TouchUpInside事件已经分配给该按钮。 When the button is pressed, it animates a menu from bottom of the screen to about half of the screen. 当按下按钮时,它将使菜单从屏幕底部到屏幕的大约一半动画化。

But I want the user to be able to swipe UP from WITHIN the button to animate the menu and swipe DOWN from WITHIN the button to animate away. 但是我希望用户能够从WITHIN按钮向上滑动以对菜单进行动画处理,而从WITHIN按钮向下滑动以进行动画处理。

I was able to figure out up and down swipe gestures but they work on the whole view. 我能够弄清楚上下滑动手势,但它们可以在整个视图中使用。
so when user swipes up anywhere on the view, it animates. 因此,当用户在视图上的任何位置向上滑动时,它都会进行动画处理。

How can I get the LocationOfTouch and limit the swipe's starting point from within the button? 如何获取LocationOfTouch并从按钮内限制滑动的起点?

This is what I have right now: 这就是我现在所拥有的:

I delclared: 我声明:

UISwipeGestureRecognizer UpSwipe;
UISwipeGestureRecognizer DownSwipe;

And then this is how I used them: 然后这就是我使用它们的方式:

    public void setupGestures() {

        this.UpSwipe = new UISwipeGestureRecognizer () {
            Direction = UISwipeGestureRecognizerDirection.Up,
            Enabled = true
        };

        this.DownSwipe = new UISwipeGestureRecognizer () {
            Direction = UISwipeGestureRecognizerDirection.Down,
            Enabled = true
        };

        UpSwipe.AddTarget (animateRecentActivityView);
        DownSwipe.AddTarget (animateAwayRecentActivityView);

        this.View.AddGestureRecognizer (UpSwipe);
        this.View.AddGestureRecognizer (DownSwipe);
    }

How can I get the LocationOfTouch and limit the swipe's starting point from within the button? 如何获取LocationOfTouch并从按钮内限制滑动的起点?

In pure Cocoa touch you can override UIView 's method 在纯可可触摸中,您可以覆盖UIView的方法

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

parameter "touches" contains a set of UITouch 参数“ touches”包含一组UITouch

call UITouch 's method 调用UITouch的方法

- (CGPoint)locationInView:(UIView *)view

you get the location of touch point 您可以获得接触点的位置

I was actually able to figure it out. 我实际上能够弄清楚。 My button was inside a view and even though I added a swipe gesture to the button, somehow it didn't work. 我的按钮在视图内,即使我向该按钮添加了滑动手势,但还是无法正常工作。 Once I removed it from the view, adding swipeGesture to the button directly worked perfectly. 将其从视图中删除后,将swipeGesture添加到按钮即可直接正常工作。

        this.UpSwipe = new UISwipeGestureRecognizer () {
            Direction = UISwipeGestureRecognizerDirection.Up,
            Enabled = true
        };

        this.DownSwipe = new UISwipeGestureRecognizer () {
            Direction = UISwipeGestureRecognizerDirection.Down,
            Enabled = true
        };

        UpSwipe.AddTarget (animateRecentActivityView);
        DownSwipe.AddTarget (animateAwayRecentActivityView);

        btnAct_HomeRecentActivity.AddGestureRecognizer (UpSwipe);
        btnAct_HomeRecentActivity.AddGestureRecognizer (DownSwipe);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM