在iOS中获取UIGestureRecognizer的操作 [英] Getting the Action of UIGestureRecognizer in iOS

查看:293
本文介绍了在iOS中获取UIGestureRecognizer的操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在NSLog中的 - tableView:didSelectRowAtIndexPath方法中打印了一个UITableviewCell的手势

I have printed a UITableviewCell's gesture in – tableView:didSelectRowAtIndexPath method in NSLog as

<UIScrollViewPanGestureRecognizer: 0x11e92080; state = Possible; cancelsTouchesInView = NO; delaysTouchesEnded = NO; view = <UITableViewCellScrollView 0x11e94bf0>; target= <(action=handlePan:, target=<UITableViewCellScrollView 0x11e94bf0>)>> 

我已将此UIScrollViewPanGestureRecognizer分配给UIGestureRecognizer以访问其属性,如下所示,

and I have assigned this UIScrollViewPanGestureRecognizer to a UIGestureRecognizer to access the properties of it as follows,

 UIGestureRecognizer *myGes=[temp.gestureRecognizers objectAtIndex:1];

我可以访问'myGes'的所有属性

I'm able to access all properties of 'myGes' as

 myGes.state;
 myGes.cancelsTouchesInView;
 myGes.delaysTouchesEnded;
 myGes.view;

除了一个名为目标的房产外。

Except one property named as target.

有没有可能进入该物业?因为我需要执行该操作。

Is there any possibility to access that property? because i need to perform that action.

任何意见或建议都将受到赞赏。

Any comments or suggestions would be appreciated.

提前感谢您。

推荐答案

有一种方法可以访问该属性 target ,但我不确定这种方法是否会通过Apple批准程序。

There is a way to gain access to the property target, but I'm not sure that this method will pass the Apple approval process.

NSMutableArray *targets = [myGes valueForKeyPath:@"_targets"];
id targetContainer = targets[0];//get first target for example
id targetOfMyGes = [targetContainer valueForKeyPath:@"_target"];
NSLog(@"%@", targetOfMyGes );//you can see reference for target object

感谢 neilco - 他的回答有助于创建解决方案。

Thanks neilco - his answer help create solution.

注意:对象的确切类 targetOfMyGes 需要自己定义。默认情况下, id - 适用于任何对象类。

Note: the exact class of the object targetOfMyGes need to define yourself. By default it id - suitable for any object class.

这篇关于在iOS中获取UIGestureRecognizer的操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆