标签: uipangesturerecognizer

使用平移手势平滑地更改动画约束

如何在iOS中使用平移手势平滑地修改约束变化?

我正在尝试开发一个屏幕,其中一个视图位于屏幕的底部.我已经为该视图添加了平移手势.在拖动该视图时,我想要更改该视图的顶部约束.平移手势仅允许在垂直和向下方向.我添加了一些拖动视图的限制.它工作但不顺利.如何使用平移手势平滑地修改约束变化?这是我的代码.

 - (void)handleGesture:(UIPanGestureRecognizer *)sender
{
    CGPoint velocity = [sender velocityInView:_locationContainer];

    [sender setTranslation:CGPointMake(0, 0) inView:self.view];

    if (fabs(velocity.y) > fabs(velocity.x)) {

        NSLog(@"velocity y %f ",velocity.y * 0.13);

        if(velocity.y < 0 && (self.locationDetailsTop.constant > minimumTop) )
        {
            NSLog(@"gesture moving Up");
            self.locationDetailsTop.constant = self.locationDetailsTop.constant - fabs(velocity.y * 0.1);
        }
        else if (self.locationDetailsTop.constant < firstTop)
        {
            NSLog(@"gesture moving Bottom");

            self.locationDetailsTop.constant = self.locationDetailsTop.constant + fabs(velocity.y * 0.1);
        }

        [self.view layoutIfNeeded];
        [UIView animateWithDuration:0.1 animations:^{
            [self.mapView setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.locationContainer.frame.origin.y)];
        }];
    }
}
Run Code Online (Sandbox Code Playgroud)

这是示例图像,我的屏幕与此类似,但在我的屏幕上,有一个地图视图而不是日历视图

在此输入图像描述

objective-c ios uipangesturerecognizer autolayout nslayoutconstraint

14
推荐指数
1
解决办法
895
查看次数

使用(自定义,交互式)视图控制器显示和解除处理滚动视图

我一直在尝试定制交互视图控制器演示和解雇(使用的组合UIPresentationController,UIPercentDrivenInteractiveTransition,UIViewControllerAnimatedTransitioning,和UIViewControllerTransitioningDelegate),并大多得到的东西我需要运作良好.

但是,有一个常见的场景我还没有在我阅读的任何教程或文档中找到解决,引出了以下问题:

...

当被解除的视图包含UIScrollView(即UITableView,UICollectionView,WKWebView等)时,通过平移手势处理自定义交互式视图控制器解除的正确方法是什么?

...

基本上,我想要的是以下内容:

  1. 通过平移它们可以交互式地禁止视图控制器.这是许多应用程序中常见的UX.

  2. 如果被解除的视图控制器包含(垂直滚动)滚动视图,则向下平移滚动该视图按预期直到用户到达顶部,之后滚动停止并且发生泛消除.

  3. 否则,滚动视图应该正常运行.

我知道这在技术上是可行的 - 我已经在其他应用程序中看到了它,例如Overcast和Apple自己的音乐应用程序 - 但是我找不到协调我的平移手势与滚动的行为的关键视图(一个或多个).

我自己的大多数尝试都集中在试图有条件地启用/禁用contentOffset.y滚动视图(或其相关的平移手势识别器)基于其滚动时让视图控制器解雇的平移手势识别器从那里接管,但这已经充满了问题和我担心我会过度思考它.

我觉得秘密主要在于以下平移手势识别器委托方法:

func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
   // ...
}
Run Code Online (Sandbox Code Playgroud)

我创建了一个简化的示例项目,该项目应该更清楚地演示场景.任何代码建议都非常欢迎!

https://github.com/Darchmare/SlidePanel-iOS

uiscrollview uiviewcontroller ios uipangesturerecognizer swift

14
推荐指数
1
解决办法
759
查看次数

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

我是ios的新手,所以如果我遗漏了一些明显的东西,我会提前道歉.

我正在制作一个拼图,我希望单个拼图在触摸时增加尺寸并减少放手.

目前我有:

-(IBAction)handlePan:(UIPanGestureRecognizer *)recognizer{
  if(recognizer.state == UIGestureRecognizerStateBegan)
  else if(recognizer.state == UIGestureRecognizerStateEnded)
}
Run Code Online (Sandbox Code Playgroud)

当平底锅开始时(也是状态开始时),拼图块增加尺寸,当平底锅结束时(如预期的那样)尺寸减小.一旦用户触摸到这件作品并且在拼图块移动之前,我希望尺寸增大.选择图块时,可以在Words With Friends中看到这一点.

我试过了

-(IBAction)handleTap:(UITapGestureRecognizer *)recognizer{
  if(recognizer.state == UIGestureRecognizerStateBegan)
  else if(recognizer.state == UIGestureRecognizerStateEnded)
}
Run Code Online (Sandbox Code Playgroud)

只有在手指抬起后才能增加拼图.

我的问题:

有一种方法可以在手指触摸拼图块后再增加拼图块的大小,然后继续摇动手势.

先感谢您.

uigesturerecognizer ios uipangesturerecognizer

13
推荐指数
3
解决办法
6016
查看次数

如何完成交互式UIViewController转换?

我一直在尝试新的iOS 7自定义转换API,并查看了我能找到的所有教程/文档,但我似乎无法根据我的具体情况来计算这些内容.

基本上我正在尝试实现的是一个视图上的UIPanGestureRecognizer,我将向上滑动并转换到VC,其视图将从底部向上滑动,而当我将手指向上移动时当前视图将向上滑动.

没有交互转换我没有遇到任何问题,但是一旦我实现了交互(平移手势),我似乎无法完成转换.

这是来自VC的相关代码,它符合出售动画控制器所需的UIViewControllerTransitionDelegate:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"Swipe"]) {
        NSLog(@"PREPARE FOR SEGUE METHOD CALLED");

        UIViewController *toVC = segue.destinationViewController;
        [interactionController wireToViewController:toVC];
        toVC.transitioningDelegate = self;
        toVC.modalPresentationStyle = UIModalPresentationCustom;
      }
}

#pragma mark UIViewControllerTransition Delegate Methods

- (id <UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:  (UIViewController *)presented                                                                   presentingController:  (UIViewController *)presenting sourceController:(UIViewController *)source {
    NSLog(@"PRESENTING ANIMATION CONTROLLER CALLED");

    SwipeDownPresentationAnimationController *transitionController = [SwipeDownPresentationAnimationController new];
    return transitionController;
}

- (id <UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed {
    NSLog(@"DISMISS ANIMATION CONTROLLER CALLED");

    DismissAnimatorViewController *transitionController = [DismissAnimatorViewController new];
    return transitionController;
}

- (id …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c uiviewcontroller ios uipangesturerecognizer

13
推荐指数
1
解决办法
1万
查看次数

ios UICollectionView检测滚动方向

我有一个collectionView.我想检测滚动方向.我有两种不同的动画风格,可以向下滚动并向上滚动.所以我必须学习滚动方向.

CGPoint scrollVelocity = [self.collectionView.panGestureRecognizer
velocityInView:self.collectionView.superview];

if (scrollVelocity.y > 0.0f)   
NSLog(@"scroll up");

else if(scrollVelocity.y < 0.0f)    
NSLog(@"scroll down");
Run Code Online (Sandbox Code Playgroud)

这只是触摸手指的工作.不适合我

objective-c uigesturerecognizer ios uipangesturerecognizer uicollectionview

13
推荐指数
3
解决办法
2万
查看次数

基于UIPinch缩放图像

我对如何做我需要的东西感到很困惑!任何帮助非常感谢!我有一个透明的图像叠加层,后面有另一个图像,它附有一个UIPanGestureRecognizer和一个UIPinchGestureRecognizer.顶部图像具有完全透明的中间,用作"玻璃"视图.我试图将底部图像裁剪为基于平移和捏合的"玻璃"部分.(见下面的图片,看看我在说什么)我已经成功地处理了平底锅作物,但是在应用捏合时也有问题正确裁剪.

我没有使用snapshotViewAfterScreenUpdates.

这是我到目前为止的代码:

 UIImage *snapshotImage;

/* draw the image of all the views below our view */
UIGraphicsBeginImageContextWithOptions(self.pendantImageView.bounds.size, NO, 0);
BOOL successfulDrawHierarchy = [self.pendantImageView drawViewHierarchyInRect:self.pendantImageView.bounds afterScreenUpdates:YES];
if ( successfulDrawHierarchy ) {
    snapshotImage = UIGraphicsGetImageFromCurrentImageContext();
} else {
    NSLog(@"drawViewHierarchyInRect:afterScreenUpdates: failed - there's nothing to draw...");
}
UIGraphicsEndImageContext();
UIImage *croppedImage;
if ( successfulDrawHierarchy ) {

    /* calculate the coordinates of the rectangle we're interested in within the returned image */
    CGRect cropRect = CGRectOffset(pendantFrame, - self.pendantImageView.frame.origin.x, - self.pendantImageView.frame.origin.y);

    /* draw the cropped …
Run Code Online (Sandbox Code Playgroud)

objective-c uiimageview ios uipangesturerecognizer uipinchgesturerecognizer

13
推荐指数
1
解决办法
214
查看次数

使用UIPanGestureRecognizer,有没有办法只经常这样做,比如在x多个像素被淘汰之后?

现在我的UIPanGestureRecognizer识别每个平移,这是很棒且必要的,但是当我使用它作为滑动手势来增加和减少变量的值时,在方法中我只想经常动作.如果每次检测到它增加1,则值会上升得太快.

有没有办法做一些事情,每10个像素的平移做这个,或类似的东西?

objective-c uigesturerecognizer ios uipangesturerecognizer

12
推荐指数
1
解决办法
4126
查看次数

将惯性添加到UIPanGestureRecognizer

我试图在屏幕上移动子视图,但我也希望为对象添加惯性或动量.
我已经拥有的UIPanGestureRecognizer代码如下.

提前致谢.

UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self       action:@selector(handlePan:)];
[self addGestureRecognizer:panGesture];

(void)handlePan:(UIPanGestureRecognizer *)recognizer
{

    CGPoint translation = [recognizer translationInView:self.superview];
    recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x,
                                     recognizer.view.center.y + translation.y);
    [recognizer setTranslation:CGPointMake(0, 0) inView:self.superview];

    if (recognizer.state == UIGestureRecognizerStateEnded) {
        [self.delegate card:self.tag movedTo:self.frame.origin];
    }
}
Run Code Online (Sandbox Code Playgroud)

再次谢谢.

momentum ios uipangesturerecognizer

12
推荐指数
1
解决办法
5322
查看次数

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

UIScrollView启用了分页功能,并且我已添加了自己的分页功能UIPanGestureRegonizer.在某些情况下,我的视图控制器将设置scrollview.scrollEnabled = NO,然后添加平移手势识别器(我没有使用scrollview自己的识别器).

因此,滚动被禁用但我正在等待来自我的手势识别器的用户触摸.当它识别时,它会调用其重新启用滚动的操作.

问题是,当用户仍然用手指按下时,我的滚动视图不会用手指跟踪.在手指抬起然后再次拖动之前,它不会开始滚动.因此,我的手势识别器正在吞咽所有触摸而不是转发任何滚动视图.

我试过切换panGestureRecognizer.cancelsTouchesInView = NO;但它似乎没有任何影响(我正在重新启用滚动时我正在删除此识别器但是我是否这样做并不能解决我的问题).我也研究了它们的delays...属性,UIGestureRecognizer但它们似乎也没有帮助.

有任何想法吗?如何让这些事件继续转发到我的滚动视图?

objective-c uiscrollview ios uipangesturerecognizer

11
推荐指数
1
解决办法
4432
查看次数

在GMSMapView中检测平移手势

我有一个GMSMapView,允许在其内部进行少量手势(平移,缩放等).我试图从这个视图实现Facebook风格的滑出菜单.从这个视图中检测平移手势同时仍然允许所有其他手势正常工作的最佳方法是什么?我确信有更好的方法可以做到这一点,但这是我到目前为止所拥有的?有什么建议?

-(void)didPan:(UIPanGestureRecognizer*)gesture
{
    static BOOL g1 = NO;

    if(gesture.state == UIGestureRecognizerStateBegan)
    {
        CGPoint location = [gesture locationInView:self];

    if(location.x < 90)
        g1 = YES;
    }

    if(gesture.state == UIGestureRecognizerStateChanged && g1)
    {
        CGPoint velocity = [gesture velocityInView:self];
        if(velocity.x > 0)
        {
            //Slide out menu
        }
        else
        {
            //Normal map view panning, zooming, etc.
        }  
    }
}
Run Code Online (Sandbox Code Playgroud)

objective-c uigesturerecognizer ios uipangesturerecognizer gmsmapview

11
推荐指数
1
解决办法
1093
查看次数