gpt4 book ai didi

ios - 限制 UIPanGestureRecognizer 的移动

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:59:59 24 4
gpt4 key购买 nike

我有一个可以使用 UIPanGestureRecognizer 拖动的 UIView 对象,但我只希望它能够向上移动屏幕的 3/4。我不希望它被剪掉,但要达到某个点并且不能再被拖动。到目前为止,我所拥有的只允许它在 Y 轴上移动(这是需要的)。

- (IBAction)panGesture:(UIPanGestureRecognizer *)recognizer
{
CGPoint translation = [recognizer translationInView:self.view];
recognizer.view.center = CGPointMake(recognizer.view.center.x,
recognizer.view.center.y + translation.y);
[recognizer setTranslation:CGPointMake(0, 0) inView:self.view];
}

感谢您的帮助。

最佳答案

所以只要检查新的Y坐标是否太小。如果 View 太小,请不要更改 View :

- (IBAction)panGesture:(UIPanGestureRecognizer *)recognizer
{
CGPoint translation = [recognizer translationInView:self.view];
[recognizer setTranslation:CGPointMake(0, 0) inView:self.view];

CGPoint center = recognizer.view.center;
center.y += translation.y;
if (center.y < self.yMin)
return;
recognizer.view.center = center;
}

关于ios - 限制 UIPanGestureRecognizer 的移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9169949/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com