Fit*_*tzy 11 methods objective-c selector ios uitapgesturerecognizer
在我的程序中,我有一个UITapGestureRecognizer
我初始化的initWithTarget: action:
.我已经通过一个选择器来调用一个名为的方法PlanetTapped: (UIImageView *)aPlanet
.这会调用方法,但我想知道如何将参数传递给action:
你performSelector: withObject
.这是不可能的?允许你向参数UIGestureRecognizer
选择器发送参数是有意义的.任何帮助表示赞赏.
ser*_*gio 13
要调用的方法的正确签名是:
-(void) PlanetTapped: (UIGestureRecognizer*)gestureRecognizer
Run Code Online (Sandbox Code Playgroud)
然后您可以通过调用以下方式访问接收到手势的视图:
-(void) PlanetTapped: (UIGestureRecognizer*)gestureRecognizer {
UIImageView* aPlanet = gestureRecognizer.view;
...
}
Run Code Online (Sandbox Code Playgroud)
实际上,这就是UIGestureRecognizer引用的内容:
手势识别器具有与其相关联的一个或多个目标 - 动作对.如果存在多个目标 - 动作对,则它们是离散的,而不是累积的.对手势的识别导致针对这些对中的每一对向目标分派动作消息.调用的操作方法必须符合以下签名之一:
- (空隙)handleGesture;
- (void)handleGesture:(UIGestureRecognizer*)gestureRecognizer;
- (void)viewDidLoad
{
UILongPressGestureRecognizer *longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPressOnPhotos:)];
[yourView addGestureRecognizer:longPressRecognizer];
}
- (IBAction)handleLongPressOnPhotos:(UILongPressGestureRecognizer *)sender{
// use "sender.view" to get the "yourView" you have long pressed
}
Run Code Online (Sandbox Code Playgroud)
希望这些能帮到你.
归档时间: |
|
查看次数: |
12728 次 |
最近记录: |