将消息传递给UIGestureRecognizer处理程序中的父级?

时间:2015-03-24 07:14:51

标签: ios objective-c methods drag-and-drop uigesturerecognizer

如果在其他地方被问到这个问题,请原谅我;我彻底搜查,找不到任何东西。我(iOS)是iOS开发的新手,我正在以Objective-C的方式学习东西。我遇到了一个问题,我试图在ViewController上拖放图像,并在1)开始和2)结束拖放时调用其中一个ViewController的方法。我的子UIImageView类有自己的UIPanGestureRecognizer,并且拖放工作完美无缺地给出了下面的代码(这是在“DrawableImageView.h”中,我的子视图类,正确地添加到ViewController {{1 }}):

[self.view addSubView:subview]

正如我所说,拖放工作完美,- (id)initWithObject:(Drawable*)obj parent:(ViewController*)viewcontroller { self = [super init]; if(self) { self.object = obj; self.userInteractionEnabled = YES; UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)]; [self addGestureRecognizer:pan]; } return self; } - (void)handlePan:(UIPanGestureRecognizer*)sender { if(sender.state == UIGestureRecognizerStateBegan) { [_parent eventAtLocationX:self.center.x Y:self.center.y]; //NSLog(@"began"); } [self.superview bringSubviewToFront:self]; CGPoint translation = [sender translationInView:self.superview]; self.center = CGPointMake( self.center.x + translation.x, self.center.y + translation.y ); [sender setTranslation:CGPointMake(0, 0) inView:self.superview]; if(sender.state == UIGestureRecognizerStateEnded) { [_parent eventAtLocationX:self.center.x Y:self.center.y]; //NSLog(@"ended"); } } s(在上面的代码中注释掉)分别在开始和结束拖放时在适当的时间执行。但是,发送给父类的消息不是。似乎根本没有完成;当我断点并尝试进入消息发送时,它会短暂跳回到iOS模拟器,然后跳到NSLog()。我还尝试将断点放在NSLog()方法本身中,并且它没有被触发,确认根本不会调用该方法。

我确信这与我对UIGestureRecognizer选择器的性质,iOS处理方式,时空性质或宇宙本身的基础的误解有关。我希望你能解释我,因为在学校/工作之夜这里已经很晚了。

并原谅n00bness。非常感谢你提前。

0 个答案:

没有答案
相关问题