欢迎光临
我们一直在努力

[Swift]模仿app首页的滚动效果

建站超值云服务器,限时71元/月

[Swift]模仿app首页的滚动效果

项目介绍:

ScrollItemView  https://github.com/agelessman/ScrollItemView

模仿各大app首页实现的滑动效果
使用UICollectionView实现

主要实现代码:
[Objective-C] 查看源文件 复制代码

class ViewController: UIViewController,UICollectionViewDelegate,UICollectionViewDataSource {

    var myCollectionView: UICollectionView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        view.backgroundColor = UIColor(red: 220/255.0, green: 220/255.0, blue: 220/255.0, alpha: 1.0)
        
        setupCollectionView()
        
    }

  
    // set up collection view
    private func setupCollectionView() {
        
        let screenW = UIScreen.mainScreen().bounds.size.width;
        var rect = view.bounds
        rect.size.height = (screenW - 15 * 2 - 10 * 3) / 2 + 30 + 10
        rect.origin.y = 100
        myCollectionView = UICollectionView(frame: rect, collectionViewLayout: collectionLayout())
        myCollectionView.backgroundColor = UIColor.whiteColor()
        myCollectionView.pagingEnabled = true
        myCollectionView.showsHorizontalScrollIndicator = true
        myCollectionView.delegate = self
        myCollectionView.dataSource = self
        view.addSubview(myCollectionView)


      myCollectionView.registerClass(CollectionViewCell.self, forCellWithReuseIdentifier: "CollectionViewCell")
      
    }
    
    // set up layout
    private func collectionLayout() -> UICollectionViewLayout {
        
        let layout = CustomLayout()
        return layout;
    }
    
    
    //MARK:- collection view data source
    func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
        
        return 1
    }
    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        
        return 26
    }
    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        
        let cell: UICollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("CollectionViewCell", forIndexPath: indexPath)
    
        return cell
    }
    
    func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
        print(indexPath.row)
    }

DMEO 直接下载:

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » [Swift]模仿app首页的滚动效果
分享到: 更多 (0)