标签: uipangesturerecognizer

拦截UIScrollView上的平移手势会中断滚动

我有一个垂直滚动UIScrollView.我还想在其上处理水平平移,同时允许默认的垂直滚动行为.我UIView在滚动视图上放置了一个透明图,并为其添加了一个平移手势识别器.这样我可以很好地获得平底锅,但滚动视图不会接收任何手势.

我已经实现了以下UIPanGestureRecognizerDelegate方法,希望仅将我的手势识别器限制为水平平底锅,但这没有帮助:

- (BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer {
    // Only accept horizontal pans here.
    // Leave the vertical pans for scrolling the content.
    CGPoint translation = [gestureRecognizer translationInView:self.view];
    BOOL isHorizontalPan = (fabsf(translation.x) > fabsf(translation.y));
    return  isHorizontalPan;
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    return (otherGestureRecognizer == _scrollView.panGestureRecognizer);
}
Run Code Online (Sandbox Code Playgroud)

uiscrollview uigesturerecognizer ios ios5 uipangesturerecognizer

40
推荐指数
3
解决办法
4万
查看次数

基于UIPanGestureRecognizer速度的UIView动画

我希望能够在屏幕上和屏幕外移动子视图,就像在iPhone照片应用程序中构建的图像之间进行浏览一样,所以当我用手指放开时子视图的屏幕超过1/2,它必须屏幕上的动画,但它也必须支持滑动,因此如果滑动/平移速度足够高,它必须在屏幕上显示动画,即使屏幕可能小于1/2.

我的想法是使用UIPanGestureRecognizer,然后测试速度.这是有效的,但是如何基于视图的当前位置和平移速度为UIView的移动设置正确的动画持续时间,使其看起来平滑?如果我设置一个固定值,与我的手指滑动速度相比,动画开始变慢或变快.

uiview uigesturerecognizer uiviewanimation ios uipangesturerecognizer

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

在CollectionView上滑动以删除

我正在尝试复制滑动以删除函数,就像在mailviewview中一样.只有这次我需要在收集视图上构建它,但我有点困难.这是一个水平滚动列表,向上滑动即可删除.我已经完成了向上滑动,但很难搞清楚我需要如何设置滑动以删除/点按以删除或忽略功能.

它看起来如下: 删除图片

所以我使用以下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 = UIEdgeInsetsMake(0, 20, 0, 30)
    collectionView.backgroundColor = UIColor.white()
    collectionView.alpha = 0.0


    //can swipe cells outside collectionview region
    collectionView.layer.masksToBounds = false


    swipeUpRecognizer = UIPanGestureRecognizer(target: self, action: #selector(self.deleteCell))
    swipeUpRecognizer.delegate = self …
Run Code Online (Sandbox Code Playgroud)

collectionview ios uipangesturerecognizer swift

23
推荐指数
2
解决办法
8330
查看次数

ios UIPanGestureRecognizer指针位置

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

- (void)pan:(UIPanGestureRecognizer *)gesture {
    NSLog(@"%f", [gesture translationInView:self].x);
}
Run Code Online (Sandbox Code Playgroud)

上面的代码将记录我当前平移的相对位置,但是如何获得我所在视图的绝对位置?

我只是想把它滑到UIImageView用户手指的任何地方.

ios uipangesturerecognizer

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

将UILongPressGestureRecognizer与UIPanGestureRecognizer组合在一起

我喜欢将UILongPressGestureRecognizer与UIPanGestureRecognizer结合使用.

UIPanGestureRecognizer应该从长按开始.有一个简单的方法吗?还是我真的要写自己的手势识别器?

我不喜欢在主屏幕上.你按下一个图标,一段时间后图标开始摇晃.之后我没有从屏幕上松开手指,我可以开始拖动手指下的图标.

cocoa-touch objective-c uigesturerecognizer uipangesturerecognizer uilongpressgesturerecogni

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

在iOS7上,在应用开始和处理程序(状态开始)之间重置平移手势转换

我有一个平移手势识别器来向上,向下,向左或向右拖动面板.当无法使用平移的方向时,我不允许识别器开始,以便触摸可以转到面板内的其他UI元素.

但是,在iOS7上,翻译有时会在gestureRecognizerShouldBegin:我的手势处理程序之间重置handlePan:

- (BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer*)panGR
{
    CGPoint trans = [panGR translationInView:self.view];
    NSLog(@"should begin trans: (%.2f, %.2f)", trans.x, trans.y);
    ...
Run Code Online (Sandbox Code Playgroud)

这个日志: should begin trans: (18.00, 0.00)

- (void)handlePan:(UIPanGestureRecognizer*)panGR
{
    CGPoint trans = [panGR translationInView:self.view];

    switch(panGR.state)
    {
        case UIGestureRecognizerStateBegan:
            NSLog(@"handlePan began trans: (%.2f, %.2f)", trans.x, trans.y);
            ...
Run Code Online (Sandbox Code Playgroud)

这个日志: handlePan began trans: (0.00, 0.00)

这意味着共享代码,以确定所述锅体(右,在这种情况下)工作在的方向gestureRecognizerShouldBegin:和允许的手势开始,但随后不能被确定handlePan:时,stateUIGestureRecognizerStateBegan.

这是iOS7中的错误还是故意改变行为以适应新的手势类型?此外,任何人都可以建议一个解决这个问题的好方法吗?

uipangesturerecognizer ios7

18
推荐指数
1
解决办法
1726
查看次数

完全滑动UITableViewCell以删除UITableView iOS 8

我想模仿滑动删除UITableViewCell的功能,就像iOS 8中的邮件应用程序一样.我不是指滑动以显示删除按钮.我指的是当你刷卡时,它会破坏3个动作,但是如果你继续向左滑动,那么电子邮件就会被删除.

在iOS 8中,UITableView有一个新方法,您可以在其中提供数据以显示任意数量的按钮:

#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 rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
        SM_LOG_DEBUG(@"Delete");
    }];
    deleteRowAction.backgroundColor = [UIColor redColor];


    return @[deleteRowAction, viewUserRowAction, viewStackRowAction];
}
#endif
Run Code Online (Sandbox Code Playgroud)

我没有看到任何API来检测你是否继续刷卡.我在UITableView.h中使用了8_0,上面的方法似乎是唯一的新方法.

我想可以监视滚动视图偏移,或添加/劫持UIPanGestureRecognizer.我只是想确保使用默认方式,如果有的话(并获得"免费"动画)

uitableview ios uipangesturerecognizer ios8

18
推荐指数
2
解决办法
6392
查看次数

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

我正在使用UIPanGestureRecognizer移动UIView对象 - 我在屏幕上拖动手指多少,我将视图向同一方向移动(仅在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)];

    }
}
Run Code Online (Sandbox Code Playgroud)

我试图使用它的图层设置视图的位置,我也尝试使用具有不同持续时间的动画设置框架,但一切都表现相同.知道为什么会出现这种延迟吗?

iphone delay ios uipangesturerecognizer

16
推荐指数
1
解决办法
5011
查看次数

阻止UIScrollView的UIPanGestureRecognizer阻止UIScreenEdgePanGestureRecognizer

我有一个UIScrollView填充我的应用程序的一个页面上的屏幕,但我想让用户从屏幕边缘平移以显示它背后的视图.问题是UIScrollView窃取了我UIScreenEdgePanGestureRecognizer在屏幕边缘的触摸.不幸的是,我无法访问UIScreenEdgePanGestureRecognizer具有UIScrollView(反之亦然)的视图控制器,因此我无法使用该方法,requireGestureRecognizerToFail:因为我无法指定应该允许哪个手势识别器失败.具有滚动视图的视图控制器是容器视图控制器的子视图控制器,其具有附加到容器视图控制器自己的视图之一的屏幕边缘平移手势识别器.

我也无法使用委托方法

-(BOOL)gestureRecognizer:shouldRequireFailureOfGestureRecognizer:
Run Code Online (Sandbox Code Playgroud)

因为UIScrollView不允许我将视图控制器设置为滚动视图的委托UIPanGestureRecognizer.

如何防止滚动视图从我自己的手势识别器中窃取边缘触摸?

iphone uiscrollview uigesturerecognizer ios uipangesturerecognizer

16
推荐指数
2
解决办法
9640
查看次数

当对象移动到某个帧时,如何停止UIPanGestureRecognizer

我有一个图像类型的对象,我正在使用UIPanGestureRecognizer移动,我需要在对象到达某个帧时停止识别UIPanGestureRecognizer.

    UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)];
    [panRecognizer setMinimumNumberOfTouches:1];
    [panRecognizer setMaximumNumberOfTouches:1];
    [panRecognizer setDelegate:self];
    [templatePhotoPlaceholderView addGestureRecognizer:panRecognizer];

-(void)move:(UIPanGestureRecognizer *)gestureRecognizer
{
    CGPoint translatedPoint = [gestureRecognizer translationInView:templatePhotoPlaceholderView];

    if([gestureRecognizer state] == UIGestureRecognizerStateBegan) {
        _firstX = [imageview center].x;
        _firstY = [imageview center].y;
    }



    translatedPoint = CGPointMake(_firstX+translatedPoint.x, _firstY+translatedPoint.y);
    //NSLog(@" Move center point :%@", NSStringFromCGPoint(translatedPoint));

    [imageview setCenter:translatedPoint];  

}
Run Code Online (Sandbox Code Playgroud)

我怎么能这样做?

iphone objective-c ipad uigesturerecognizer uipangesturerecognizer

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