我有一个UIView C是UIView B的子视图,它是UIView A的子视图。我使用一个名为“selectorX”的选择器向UIView C添加一个UIPanGestureRecogizer,当UIView C离开UIView A帧时我想要它,然后它的superview更改为UIView A,我也想用另一个选择器“selectorY”更改其UIPanGestureRecognizer。
这是我的代码:
-(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];
}
}
一切顺利但2 UIPanGestureRecognizers之间的过渡并不是连续的。当uiViewC更改其superView时,拖动操作将停止。我必须从屏幕上取下手指并再次开始运动。我该怎么做才能使机芯继续运转? 非常感谢你
答案 0 :(得分:0)
为了获得连续移动,我没有从uiViewB中删除uiViewC,我只是将它添加到uiViewA并解决了问题。