本文介绍了手势识别器和块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以将块与手势识别器一起使用吗?看来并非如此.例如,这不起作用:

Can we use blocks with Gesture Recognizers? It doesn't appear so. For example, this does not work:

UITapGestureRecognizer *tapped = [[UITapGestureRecognizer alloc] initWithTarget: self
     action:^(id sender) {
     }
];

我是否缺少某些东西,还是UIGestureRecognizer类不支持块?

Am I missing something, or are blocks just not supported by the UIGestureRecognizer class?

推荐答案

但是,这应该:

UITapGestureRecognizer *tapped = [[UITapGestureRecognizer alloc] initWithTarget:[^{
    // do stuff
} copy] action:@selector(invoke)];

但是,由于它是私有方法,因此您不应该这样做.

You shouldn't probably do this, however, since it's a private method.

这篇关于手势识别器和块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-20 01:08