【发布时间】: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 你的方法正在执行?。
标签: ios objective-c uiview uigesturerecognizer