我知道像这样的问题有很多答案,GitHub 上有很多库,但我只是想让它简单明了。我只想将菜单移出并使其跟随我的手指。该部分有效,但 View 最初并没有顺利滑出……它只是出现在我手指所在的位置。这是我拥有的:
//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 后平滑地滑出到手指位置……有什么建议吗?
最佳答案
我用过:
UISwipeGestureRecognizer *sgr = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(rightRevealToggle:)];
sgr.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:sgr];
检查一下,也许更容易
关于ios - UIPanGestureRecognizer 滑动UIView动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24737328/