Tag: uipangesturerecognizer

UIPanGestureRecognizer不能平滑地移动对象

我试图使用UIPanGestureRecognizer移动我的对象,但我似乎无法让它顺利移动。 当我朝一个特定的方向移动并改变到相反时,它不会立即作出反应。 我认为这个值可能有问题,因为它在“ – >”方向是正值,而在“ – ”方向是负值。 我的代码如下: – (void)panDetected:(UIPanGestureRecognizer *)panRecognizer { CGPoint pointA = [panRecognizer locationInView:self.view]; CGPoint pointB = [panRecognizer translationInView:self.view]; if(panRecognizer.state == UIGestureRecognizerStateEnded || panRecognizer.state == UIGestureRecognizerStateChanged) { _camera.x += pointB.x * 0.0001f; } } 有没有人有更合适的方法来解决这个任务? 提前致谢。

我已经使UIPanGestureRecognizer只检测大多数垂直平底锅,我如何使它只能检测到真正的垂直平底锅?

我刚刚实现了这个: – (BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)panGestureRecognizer { CGPoint translation = [panGestureRecognizer translationInView:someView]; return fabs(translation.y) > fabs(translation.x); } (如此处所述) 但是,如果用户垂直摆动对angular线,它将开始。 我如何让宽容更严格,认为是垂直的? 基本上,下面的图片描述了我之后。 第一个图是现在检测到的,这个区域内的任何东西,第二个是我想要的。

iOS:如何同步两个UIScrollview

我有两个水平的UIScrollview 。 我想在用户拖动手指时同步滚动。 这是我的代码: self.topScrollView = [[UIScrollView alloc] initWithFrame:CGRectZero]; self.topScrollView.delegate = self; self.topScrollView.bounces = YES; self.bottomScrollView = [[UIScrollView alloc] initWithFrame:CGRectZero]; self.bottomScrollView.delegate = self; self.bottomScrollView.bounces = YES; … – (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { if (scrollView == self.topScrollView) { self.bottomScrollView.delegate = nil; } else { self.topScrollView.delegate = nil; } … } – (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate { … self.topScrollView.delegate […]

当我将UIPanGestureRecognizer和自动布局结合在一起时,我的UIViews变得糟糕透顶

我想要一个球跟踪我的手指,当我沿着一个圆形轨迹拖动iPhone或iPad上的每个允许的设备方向时。 当一个设备被旋转时,视图看起来是正确的居中,但是球不会停留在圆周上,当我拖动它的时候它似乎会去任何地方。 编辑 马丁R的答案现在显示这个要求。 我唯一的附加代码更改是删除不必要的声明var shapeLayer = CAShapeLayer() 这个例子中的math是非常有意义的,直到我试图将球和轨迹同时约束到视图的中心,并在运行时将球的中心坐标加上偏移量。 我遵循这些关于如何约束视图的build议 。 有三件事我不明白。 首先,根据两个variablestrackRadius和angular度theta计算圆的圆周,并使用theta sin和cos来找出x和y坐标,这样就不会使球处于正确的位置。 其次,使用atan来查看视图中心与触摸点之间的angular度theta ,使用trackRadius和theta来查找x和y坐标不会将球放置或移动到沿着圆周的新位置。 第三,每当我拖动球,在debugging区域的消息说, Xcode is Unable to simultaneously satisfy constraints ,虽然没有约束问题报告拖动之前。 这里可能有一个以上的问题。 我的大脑开始受到伤害,如果有人能指出我做错了什么,我会很感激。 这是我的代码。 import UIKit class ViewController: UIViewController { override var supportedInterfaceOrientations: UIInterfaceOrientationMask { return .all } var shapeLayer = CAShapeLayer() let track = ShapeView() var ball = ShapeView() var […]

在UIPanGestureRecognizer和重新启用的UIScrollView之间连续滚动

我有一个启用分页的UIScrollView ,我已经添加了我自己的UIPanGestureRegonizer 。 在某些情况下,我的视图控制器将设置scrollview.scrollEnabled = NO ,然后添加平移手势识别器(我不使用scrollview自己的识别器)。 所以,滚动禁用,但我正在等待我的手势识别器的用户触摸。 当它识别时,它会调用其重新启用滚动的操作。 问题是,当用户仍然有一个手指下来,我的滚动视图不会用手指跟踪。 直到手指抬起然后再次拖动,它才开始滚动。 所以我的手势识别器吞咽所有的触摸,不转发任何滚动视图。 我试过切换panGestureRecognizer.cancelsTouchesInView = NO; 但它似乎没有任何效果(我目前正在删除这个识别器,只要我重新启用滚动,但是否我这样做或不解决我的问题)。 我也研究了UIGestureRecognizer的delays…属性,但它们似乎也没有帮助。 有任何想法吗? 我怎样才能让这些事件继续前进到我的滚动视图?

如何以编程方式快速发送pangesture

我有一个panGesturefunction的视图,但我需要发送一个平移手势从一个点到另一个编程。 有没有办法做到这一点迅速使用具有特定时间间隔的animation? 这是我尝试以编程方式调用平移手势: var upPanPoint = CGPoint(x: contentView.center.x, y: contentView.center.y + 500) var upPan = panGestureRecognizer.setTranslation(upPanPoint, inView: self) onSwipe(upPan) 这是识别平移手势的代码: func onSwipe(panGestureRecognizer : UIPanGestureRecognizer!) { let view = panGestureRecognizer.view! print(view) switch (panGestureRecognizer.state) { case UIGestureRecognizerState.Began: if (panGestureRecognizer.locationInView(view).y < view.center.y) { self.viewState.rotationDirection = .RotationAwayFromCenter } else { self.viewState.rotationDirection = .RotationTowardsCenter } case UIGestureRecognizerState.Ended: self.finalizePosition() default: let […]

如何基于平移手势速度将angular度冲击应用于Sprite Kit节点

我在这里要做的是旋转一个SKSpriteNode围绕其锚点,并使其速度和方向与平移手势匹配。 所以如果我的平移手势是围绕精灵的顺时针方向,那么精灵顺时针旋转。 我用我的代码的问题是,它适用于精灵之下从左到右/从右到左的平底锅,但是当我尝试和垂直平移,并且它使得精灵旋转错误的方式,如果我泛精灵。 这是我到目前为止 – let windmill = SKSpriteNode(imageNamed: "Windmill") override func didMoveToView(view: SKView) { /* Setup gesture recognizers */ let panGestureRecognizer = UIPanGestureRecognizer(target: self, action: "handlePanGesture:") self.view?.addGestureRecognizer(panGestureRecognizer) windmill.physicsBody = SKPhysicsBody(circleOfRadius: windmill.size.width) windmill.physicsBody?.affectedByGravity = false windmill.name = "Windmill" windmill.position = CGPoint(x: self.frame.size.width / 2, y: self.frame.size.height / 2) self.addChild(windmill) } func handlePanGesture(recognizer: UIPanGestureRecognizer) { if […]

禁用平移手势,如果超出检测范围

我有一个UIView我想上下移动屏幕,但是我只想让它平移,以便当它在正常位置(0,0)时不能拖动视图, 我试图检测识别器的中心何时不是视图高度的一半,然而视图是不可移动的,并且中心总是高度的一半(在这种情况下是230)。 有任何想法吗? – (IBAction)panDetected:(UIPanGestureRecognizer *)recognizer { CGPoint translation = [recognizer translationInView:self.view]; NSLog(@"\ncenter.y: %f\ntranslation.y: %f\n", recognizer.view.center.y, translation.y); if (recognizer.view.center.y > ([[UIScreen mainScreen] bounds].size.height – 20)/2) { return; } recognizer.view.center = CGPointMake(recognizer.view.center.x, recognizer.view.center.y + translation.y); [recognizer setTranslation:CGPointMake(0, 0) inView:self.view]; }

用垂直平移手势水平滚动UIScrollView

我试图实现一个UIScrollView水平平移滚动浏览图片的滚动视图,但垂直平移执行另一个行动,我有。 现在我有一个UIScrollView的分页与垂直滚动禁用,适用于滚动通过图片工作得很好,但是要疯狂试图find一种方法来拦截垂直平底锅,并调用我自己的方法,而不是垂直平底锅只是被吃掉scrollview。 我能做到 UIPanGestureRecognizer *panUp = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)]; [self.scrollView addGestureRecognizer:panUp]; [scrollView.panGestureRecognizer setEnabled:NO]; 这使我可以完全控制我的handlePanGesture:方法中的平移,但这并不是特别有用,因为那样我觉得我基本上会重写所有我试图避免的滚动逻辑。 任何帮助或指导如何实现这一点,将不胜感激。 谢谢!

如何在UIPanGestureRecognizer方法中获取当前触点和上一个触点?

我是新来的iOS,我在我的项目中使用UIPanGestureRecognizer 。 我在拖动视图时需要获取当前触摸点和上一个触摸点。 我正在努力得到这两点。 如果我使用touchesBegan方法而不是使用UIPanGestureRecognizer ,我可以通过下面的代码得到这两点: – (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ CGPoint touchPoint = [[touches anyObject] locationInView:self]; CGPoint previous=[[touches anyObject]previousLocationInView:self]; } 我需要在UIPanGestureRecognizer事件触发方法中获得这两点。 我怎样才能做到这一点? 请指导我。