滑动手势 iPhone

发布于 2024-11-02 07:14:34 字数 806 浏览 5 评论 0原文

我在处理 iPhone 上的滑动时遇​​到一些麻烦,我在界面中创建了 UISwipeGestureRecognizer var:

UISwipeGestureRecognizer *swipeRecognizer;

并在控制器中创建了 viewDidLoad 方法

- (void)viewDidLoad
{
    [super viewDidLoad];


    // Horizontal swipe
    swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self 
                                                                          action:@selector(swipeMethod:)];
    swipeRecognizer.direction = UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft; 
    [self addGestureRecognizer:swipeRecognizer];
}

和我的方法处理滑动的方法是:

-(void)swipeMethod: (UISwipeGestureRecognizer *) sender
{
    NSLog(@"Swipe!");   
}

当我运行代码并进行滑动时,我什么也没有得到?我应该得到:刷卡!

谢谢。

I have some trouble to handle swipe on iPhone, I create in my interface a UISwipeGestureRecognizervar:

UISwipeGestureRecognizer *swipeRecognizer;

and in my controller : viewDidLoad method

- (void)viewDidLoad
{
    [super viewDidLoad];


    // Horizontal swipe
    swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self 
                                                                          action:@selector(swipeMethod:)];
    swipeRecognizer.direction = UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft; 
    [self addGestureRecognizer:swipeRecognizer];
}

And my method to handle swipe is :

-(void)swipeMethod: (UISwipeGestureRecognizer *) sender
{
    NSLog(@"Swipe!");   
}

When I run my code and do a swipe I got nothing? I'm supposed to get : Swipe!

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

生死何惧 2024-11-09 07:14:34

我很惊讶它不会因无法识别的选择器错误而崩溃。尝试将识别器添加到您的视图而不是视图控制器:

[self.view addGestureRecognizer:swipeRecognizer]

I'm surprised that doesn't crash with an unrecognized selector error. Try adding the recognizer to your view instead of to your view controller:

[self.view addGestureRecognizer:swipeRecognizer]
时光与爱终年不遇 2024-11-09 07:14:34

swipeRecognizer.direction = UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft;

这有效吗?

不是要为每个方向添加两个gestureRecognizer吗?

swipeRecognizer.direction = UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft;

Does this work?

Don't you have to add two gestureRecognizer for each direction?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文