简体   繁体   中英

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".

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. When uiViewC changes its superView, the drag action stops. 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中,它解决了该问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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