Tag: uipangesturerecognizer

UIPanGestureRecognizer在触摸时立即执行某些操作

我是新来的ios,所以我提前道歉,如果我失去了一些明显的东西。 我正在创造一个谜题,我希望单个拼图在触摸时增加尺寸,减less放手。 目前我有: -(IBAction)handlePan:(UIPanGestureRecognizer *)recognizer{ if(recognizer.state == UIGestureRecognizerStateBegan) else if(recognizer.state == UIGestureRecognizerStateEnded) } 当盘子开始时(这也是开始的时候),拼图块增加了尺寸,当盘子结束时(如所期望的),拼图块的尺寸减小。 我希望一旦用户触摸了这个棋子,拼图块移动之前,尺寸就会增加。 当select一个瓷砖时,这在Words With Friends中看到。 我努力了 -(IBAction)handleTap:(UITapGestureRecognizer *)recognizer{ if(recognizer.state == UIGestureRecognizerStateBegan) else if(recognizer.state == UIGestureRecognizerStateEnded) } 这只会在手指抬起之后才会增加拼图。 我的问题: 有一种方法可以在手指碰到拼图块后增加拼图的尺寸,然后继续平移手势。 先谢谢你。

有了UIPanGestureRecognizer,有没有一种方法只能像许多像素被淘汰之后那么频繁?

现在我的UIPanGestureRecognizer可以识别每个单独的平移,这是非常好的必要条件,但是由于我用滑动手势来增加和减less一个variables的值,所以我只想每隔一段时间就采取行动。 如果我每次检测到增加1,那么这个值就会变得太快。 有没有办法做像这样的每10个像素的像这样或类似的东西?

为什么使用UIPanGestureRecognizer移动对象时会有延迟

我使用UIPanGestureRecognizer移动UIView对象 – 我在屏幕上拖动手指的方式有多less,我将视图以相同的方向移动(仅在X – 左侧或右侧,Y没有改变)。 它工作正常,但(非常明显)延迟。 以下是处理UIPanGestureRecognizer事件的方法: -(void)movePages:(UIPanGestureRecognizer *)sender { if(switchingMode == 1){ if([sender state] == UIGestureRecognizerStateBegan){ fingerStartPosition = [sender locationInView:self.view].x; viewStartPosition = [[viewControllers objectAtIndex:activeViewControllerIndex] view].center; } [[[[viewControllers objectAtIndex:activeViewControllerIndex] view] layer] setPosition:CGPointMake(viewStartPosition.x – (fingerStartPosition – [sender locationInView:self.view].x) , viewStartPosition.y)]; } } 我试图用它的图层设置视图的位置,我也尝试使用不同持续时间的animation设置框架,但是所有的performance都是一样的。 任何想法为什么这个延迟发生?

ios UIPanGestureRecognizer指针的位置

UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)]; [self addGestureRecognizer:panRecognizer]; – (void)pan:(UIPanGestureRecognizer *)gesture { NSLog(@"%f", [gesture translationInView:self].x); } 上面的代码会logging我当前平移的相对位置,但是我怎样才能得到我所在视图的绝对位置呢? 我只是想将UIImageView滑动到用户手指的任何位置。

平移手势会干扰滚动

我有三个视图控制器是UIScrollView的一部分。 我希望能够在三者之间滑动,尽pipe其中一个视图控制器有一个UIPanGestureRecognizer。 我使用这个平移手势识别器来允许用户上下拖动他们的手指来增加和减小矩形UIView的高度。 因此,这个UIPanGestureRecognizer只需要知道向上/向下平移,滚动视图可以使用水平平移。 一个例子就是主屏幕。 您可以向左或向右滑动,也可以向下滑动以获得聚光灯。 我想要这种机制。 这是我的泛代码: – (void)pan:(UIPanGestureRecognizer *)aPan; // When pan guesture is recognised { CGPoint location = [aPan locationInView:self.view]; // Location of finger on screen CGRect secondRect = CGRectMake(210.0, 45.0, 70.0, 325.0); // Rectangles of maximimum bar area CGRect minuteRect = CGRectMake(125.0, 45.0, 70.0, 325.0); CGRect hourRect = CGRectMake(41.0, 45.0, 70.0, […]

如何确定平底手势的真实最终速度?

当使用UIPanGestureRecognizer并检测到UIGestureRecognizerStateEnded ,手势的速度不是真实的速度。 相反,这是以前调用我的操作方法的旧速度。 我怎样才能访问手势结束时的真实速度? 我创build我的UIPanGestureRecognizer像这样: UIPanGestureRecognizer* panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureRecognized:)]; [panGestureRecognizer setMaximumNumberOfTouches:2]; [panGestureRecognizer setMinimumNumberOfTouches:1]; [panGestureRecognizer setDelegate:self]; [panGestureRecognizer setDelaysTouchesBegan:NO]; [panGestureRecognizer setDelaysTouchesEnded:NO]; [panGestureRecognizer setCancelsTouchesInView:NO]; [self addGestureRecognizer:panGestureRecognizer]; 我的行动方法的开始在这里: – (IBAction) panGestureRecognized:(UIPanGestureRecognizer *)recognizer { UIGestureRecognizerState state = recognizer.state; CGPoint gestureTranslation = [recognizer translationInView:self]; CGPoint gestureVelocity = [recognizer velocityInView:self]; [CBAppDelegate log:@"panGestureRecognized: state: %s\n translation: (%f, %f)\n velocity: (%f, […]

全面轻扫UITableViewCell删除UITableView iOS 8

我想模仿滑动来删除UITableViewCell的function,就像iOS 8中的邮件应用程序。我不是指滑动来显示删除button。 我指的是当你滑动时,它会抛弃3个动作,但是如果你继续向左滑动,电子邮件将被删除。 在iOS 8中,UITableView有一个新的方法,你可以提供数据来显示任意数量的button: #ifdef __IPHONE_8_0 – (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewRowAction *viewStackRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Stack" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) { SM_LOG_DEBUG(@"View Stack Action"); }]; viewStackRowAction.backgroundColor = [UIColor radiusBlueColor]; UITableViewRowAction *viewUserRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"User" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) { SM_LOG_DEBUG(@"View User Action"); }]; viewUserRowAction.backgroundColor = [UIColor radiusLightBlueColor]; UITableViewRowAction *deleteRowAction = [UITableViewRowAction […]

使用类似于新的Google Maps iOS应用程序的上滑视图,可能会遇到多个UIPanGestureRecognizer问题

我试图重现新的iOS谷歌地图应用程序的上滑菜单的行为。 所以基本上这是一个视图,你可以上下滑动到某个点,或者滑动到某个点。 此视图也可以像分页滚动视图一样向右和向左滑动。 它应该上下滚动或滑动到一边,但不是在同一时间。 经过大量的研究和testing,我得到的东西很接近,但并不像需要的那样工作。 我的实现是一个320×400的框架的UIScrollView和960×400分页滚动的内容视图。 然后我添加一个UIPanGestureRecognizer来处理整个视图的上移。 这是PanRecognizer的handleTouch IBAction: – (IBAction)handlePan:(UIPanGestureRecognizer *)sender { NSLog(@"Panning"); CGPoint translatedPoint = [(UIPanGestureRecognizer*)sender translationInView:self.view]; if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateBegan) { _firstX = [[sender view] center].x; _firstY = [[sender view] center].y; } if (!IS_IPHONE_5) { if (_firstY < 216) translatedPoint = CGPointMake(_firstX, 216); else translatedPoint = CGPointMake(_firstX, _firstY+translatedPoint.y); } else { if […]

拖动UIButton,而不移动到中心

所以我find了如何使用UIPanGestureRecognizer使button可拖动。 但我知道如何做的唯一方法是通过存储和拖动button的中心。 这个问题是,如果你尝试从一个angular落拖动button,button会立即从angular落移动到中心。 我正在寻找的是一个解决scheme,将保持我的手指在选定的地方,而没有立即locking中心移动。 我目前使用的代码是: func buttonDrag(pan: UIPanGestureRecognizer) { print("Being Dragged") if pan.state == .began { print("panIF") buttonCenter = button.center // store old button center }else { print("panELSE") let location = pan.location(in: view) // get pan location button.center = location // set button to where finger is } } 提前致谢。

在CollectionView上滑动即可删除

我试图复制滑动删除函数,如在邮件tableview中。 只有这一次,我需要在collectionview上构build它,但是我有点困难。 这是一个水平滚动列表刷卡删除。 我已经得到了刷卡工作,但很难搞清楚我需要如何设置刷卡删除/点击删除或忽略function。 它看起来像下面这样: 所以我使用以下collectionview: func buildCollectionView() { let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout() layout.scrollDirection = .horizontal layout.minimumInteritemSpacing = 0; layout.minimumLineSpacing = 4; collectionView = UICollectionView(frame: CGRect(x: 0, y: screenSize.midY – 120, width: screenSize.width, height: 180), collectionViewLayout: layout) collectionView.dataSource = self collectionView.delegate = self collectionView.register(VideoCell.self, forCellWithReuseIdentifier: "videoCell") collectionView.showsHorizontalScrollIndicator = false collectionView.showsVerticalScrollIndicator = false collectionView.contentInset = […]