手指离开手机屏幕后UIView自动向上滑动
Posted
技术标签:
【中文标题】手指离开手机屏幕后UIView自动向上滑动【英文标题】:UIView sliding upward direction automatically after removing the finger from the phone screen 【发布时间】:2016-07-25 05:14:28 【问题描述】:这是我目前正在处理的屏幕。正如您在下面看到的那样,我使用了标签和四个按钮的 UIView。在此之下,我使用了表格视图来显示菜单。我使用 SwipeGesture 来上下滑动视图。每当我触摸背景图像时,我现在想要的 UIView 完全向下滑动并且当我移开手指时 从屏幕上,UIView 会自动反弹到如图所示的相同位置。谁能帮帮我??
这是我迄今为止工作的代码-
UISwipeGestureRecognizer *gestureRecognizerUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeHandlerUp:)];
[gestureRecognizerUp setDirection:(UISwipeGestureRecognizerDirectionUp)];
[self.subview addGestureRecognizer:gestureRecognizerUp];
UISwipeGestureRecognizer *gestureRecognizerDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeHandleDown:)];
[gestureRecognizerDown setDirection:(UISwipeGestureRecognizerDirectionDown)];
[self.subview addGestureRecognizer:gestureRecognizerDown];
- (void)swipeHandlerUp:(UISwipeGestureRecognizer *)sender
if (sender.direction == UISwipeGestureRecognizerDirectionUp)
[UIView animateWithDuration:0.3 animations:^
CGPoint Position = CGPointMake(self.view.frame.origin.x, self.view.frame.origin.y+20);
self.subview.frame = CGRectMake(Position.x , Position.y , self.subview.frame.size.width, self.subview.frame.size.height);
[self.navigationController popViewControllerAnimated:YES];
];
- (void)swipeHandleDown:(UISwipeGestureRecognizer *)sender
if (sender.direction == UISwipeGestureRecognizerDirectionDown)
[UIView animateWithDuration:0.3 animations:^
CGPoint Position = CGPointMake(self.view.frame.origin.x , self.view.frame.origin.y+430);
self.subview.frame = CGRectMake(Position.x , Position.y , self.subview.frame.size.width, self.subview.frame.size.height);
[self.navigationController popViewControllerAnimated:YES];
];
【问题讨论】:
你能不能用touchEnd方法来识别手指松开。 我不太清楚。这行得通吗?? 在您的 swipeHandlerUp 方法中,您必须向上移动框架。因此,对于 Y 轴,请执行以下操作 - self.view.frame.origin.y -200。然后对于 swipeHandleDown 方法,-self.view.frame.origin.y +200。 对我不起作用 :( @Signare 显示任何错误? @pri 你的方法正在执行?。 【参考方案1】:你可以在-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event;
这样做
并确保取消选择所有三个手势行为,例如您的 swipeGestures。
Your_Swipe_gesture_Object.delaysTouchesBegan = NO;
Your_Swipe_gesture_Object.delaysTouchesEnded = NO;
Your_Swipe_gesture_Object.cancelsTouchesInView = NO;
【讨论】:
【参考方案2】:-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
[super touchesBegan:touches withEvent:event];
[UIView animateWithDuration:0.3 animations:^
CGPoint Position = CGPointMake(self.view.frame.origin.x, self.view.frame.origin.y+20);
self.subview.frame = CGRectMake(Position.x , Position.y , self.subview.frame.size.width, self.subview.frame.size.height);
[self.navigationController popViewControllerAnimated:YES];
];
-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
[super touchesBegan:touches withEvent:event];
[UIView animateWithDuration:0.3 animations:^
CGPoint Position = CGPointMake(self.view.frame.origin.x , self.view.frame.origin.y+430);
self.subview.frame = CGRectMake(Position.x , Position.y , self.subview.frame.size.width, self.subview.frame.size.height);
[self.navigationController popViewControllerAnimated:YES];
];
【讨论】:
抱歉 saurabh 不是子视图必须通过拖动视图完全下降。当手指松开时,它应该会自动出现 当你拖动手指查看..你想查看显示吗? 我不明白你在说什么。 这里没有办法发送视频吗?这样我就可以展示我到底想要什么 @pri 我的代码中的主要问题是什么?在我身边工作得很好。以上是关于手指离开手机屏幕后UIView自动向上滑动的主要内容,如果未能解决你的问题,请参考以下文章