【发布时间】:2014-07-14 13:10:49
【问题描述】:
我知道在 GitHub 上有很多此类问题的答案以及许多库,但我只是想让它保持轻松和简单。我只想将菜单移出并使其跟随我的手指。那部分有效,但视图最初并没有顺利滑出……它只是出现在我手指所在的位置。这是我所拥有的:
//viewDidLoad
UIPanGestureRecognizer *panSettings = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePan:)];
[panSettings setDelegate:self];
[self.view addGestureRecognizer:panSettings];
UIView *container = [[UIView alloc]initWithFrame:CGRectMake(320, 0, self.view.frame.size.width, self.view.frame.size.height)];
//...drop shadows and such...
[self.view addSubview:_container];
- (void)handlePan:(UIPanGestureRecognizer *)sender{
CGPoint velocity = [sender velocityInView:self.view];
CGPoint translation = [sender translationInView:self.view];
if (velocity.x < 0 && translation.x < -50) {
if (_container.frame.origin.x != 0) {
panCoord = [sender locationInView:self.view];
[UIView animateWithDuration:0.3 animations:^{
_container.frame = CGRectMake(panCoord.x-100, 0, self.view.frame.size.width, self.view.frame.size.height);
}];
}
}
}
处理平底锅:我想检查幻灯片的走向,检查多长时间并检查容器的位置。一旦滑动向左更负然后-50,我想让它顺利滑出到手指位置......有什么建议吗?
【问题讨论】:
-
你的 UIView 动画在哪里?
-
@SantaClaus 我也尝试了 UIView 动画,它仍然具有仅出现在手指位置的相同效果。
-
您也可以使用触控方法(即触控开始、触控移动、触控结束)来完成这些操作
-
@yourwish 我看到了这些示例...要使用触摸事件,我需要子类化 UIView 并将这些方法添加到该子类中?因为我无法让触摸事件在
self.view中工作 -
使用你自己创建的委托方法来通知另一个类你的触摸。
标签: ios objective-c uiview uigesturerecognizer