简体   繁体   English

进行平移手势时更改选择器

[英]Change selector while a pan gesture is going on

I have a UIView C which is a subview of UIView B wich is a subview of UIView A. I add a UIPanGestureRecogizer to UIView C with a selector called "selectorX" and I want that when UIView C goes out of UIView A frame, then its superview changes to UIView A and I want also to change its UIPanGestureRecognizer with another selector "selectorY". 我有一个UIView C,它是UIView的子视图,而又是UIView A的子视图。我向UIView C添加了一个名为“ selectorX”的选择器,并希望当UIView C离开UIView A框架时,超级视图更改为UIView A,我还希望使用另一个选择器“ selectorY”来更改其UIPanGestureRecognizer。

This is my code: 这是我的代码:

-(void)selectorX:(UIPanGestureRecognizer*)sender{


     CGPoint translation = [sender translationInView:self.view];
     sender.view.center = CGPointMake(sender.view.center.x, sender.view.center.y +translation.y);
    [sender setTranslation:CGPointMake(0, 0) inView:sender.view];

    UIView *uiViewC=(ImagenFichaView *)sender.view;
    if (sender.view.center.y+translation.y<-50) {
         [uiViewC removeFromSuperView]
         CGPoint newCenter=[sender locationInView:uiViewA];
         [uiViewA addSubview:uiViewC];
         uiViewC.center=newCenter;
         UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(selectorY:)];
    panRecognizer.delegate=self;
    [uiViewC removeGestureRecognizer:sender];
    [uiViewC addGestureRecognizer:panRecognizer];
    }

} }

Everything goes well but the transition between the 2 UIPanGestureRecognizers is not continuous. 一切顺利,但是两个UIPanGestureRecognizer之间的转换不是连续的。 When uiViewC changes its superView, the drag action stops. uiViewC更改其superView时,拖动动作将停止。 I have to take off my finger from the screen and start the movement again. 我必须从屏幕上移开手指,然后重新开始运动。 What can I do to make the movement continuos? 我该怎么做才能使运动连续进行? Thank you very much 非常感谢你

为了获得连续的运动,我没有从uiViewB中删除uiViewC,而是将其添加到uiViewA中,它解决了该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM