Giter VIP home page Giter VIP logo

tbdemo's Introduction

仿照天猫App写的一个长按商品弹框的Demo

前两天买衣服发现的,长按弹出商品详情带分享收藏之类,觉得挺好玩的,果然大团队,果然别人家的产品,仿着写一个,没什么技术含量,纯闲着没事练手,手痒呀。。。

核心代码就这几句:

// 1.在UICollectiong上添加长按手势
    UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPressGesture:)];
    longPress.allowableMovement = YES;
    [self.collectionView addGestureRecognizer:longPress];
- (void)longPressGesture:(UILongPressGestureRecognizer *)gestureRecognizer {
    // 2.判断是否是确定了手势类型,如果是确定手势类型,就继续往下走,
    //   这里之前使用了UIGestureRecognizerStateEnded 效果并不好,要松开手指之后才能触发方法
    if (gestureRecognizer.state != UIGestureRecognizerStateBegan) {
        return;
    }
    // 3.拿到点击的位置,通过位置获取indexPath
    CGPoint p = [gestureRecognizer locationInView:self.collectionView];
    NSIndexPath *indexPath = [self.collectionView indexPathForItemAtPoint:p];

    if (indexPath == nil){

    } else {
        // 4.这里是自己简单写的弹框。
        LongTouchView *touchView = [LongTouchView sharManager];
        touchView.iconIMV.image = [UIImage imageNamed:self.dataSource[indexPath.row]];
        touchView.nameLabel.text = self.dataSource[indexPath.row];
        [touchView show];
    }
}

tbdemo's People

Contributors

yvanliu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.