Swift 类似网易新闻的滑动菜单

Swift 类似网易新闻的滑动菜单,第1张

概述gif.gif gif 可以右键在新的标签页中打开查看 简单实现类似这种的 滑动菜单 新手Swift新手 大神就别看了 import UIKitclass HomeViewController: UIViewController,UICollectionViewDelegate,UICollectionViewDataSource,UIScrollViewDelegate { let
gif.gif

gif 可以右键在新的标签页中打开查看

简单实现类似这种的 滑动菜单 新手Swift新手 大神就别看了

import UIKitclass HomeVIEwController: UIVIEwController,UICollectionVIEwDelegate,UICollectionVIEwDataSource,uiscrollviewdelegate {    let WIDTH = UIScreen.mainScreen().bounds.wIDth / 375 let HEIGTH = UIScreen.mainScreen().bounds.height / 667 let SCREENWIDTH = UIScreen.mainScreen().bounds.wIDth let SCREENHEIGTH = UIScreen.mainScreen().bounds.height var collectionVIEw: UICollectionVIEw!    var buttonsArray: NSMutableArray!    var TitlesArray: NSMutableArray!    var lineVIEw: UIVIEw!    overrIDe func vIEwDIDLoad() {        super.vIEwDIDLoad()        self.automaticallyAdjustsScrollVIEwInsets = false        self.navigationController?.automaticallyAdjustsScrollVIEwInsets = false        self.initbuttons()        self.initCollectionVIEw()    }    func initbuttons() {        buttonsArray = NSMutableArray()        TitlesArray = ["分类","品牌","首页","专题","品牌"]        for var i = 0;i<TitlesArray.count;i++ { let button = UIbutton.init(type: .System)            button.frame = CGRectMake(SCREENWIDTH * CGfloat (i) / 5.0,SCREENWIDTH / 5.0,40 * HEIGTH)            button.tag = i            button.backgroundcolor = UIcolor.blackcolor()            button.setTitlecolor(UIcolor.lightGraycolor(),forState: .normal)            if i == 2 {            button.TitleLabel?.Font = UIFont.systemFontOfSize(16.0 * WIDTH)            button.whitecolor(),0)">.normal)            }            button.systemFontOfSize(15.0 * WIDTH)            button.setTitle(TitlesArray[i] as? String,0)">.normal)            button.addTarget(self,action: "click:",forControlEvents: .touchUpInsIDe)            self.vIEw.addSubvIEw(button)            buttonsArray.addobject(button)        }        lineVIEw = UIVIEw.init(frame: CGRectMake(15 * WIDTH + (SCREENWIDTH / 5.0) * 2,38 * HEIGTH,SCREENWIDTH / 5.0 - 30 * WIDTH,2 * HEIGTH))        lineVIEw.whitecolor()        self.addSubvIEw(lineVIEw)    }    func click (btn: UIbutton) {        for btt in buttonsArray {            btt.TitleLabel?!.systemFontOfSize(15)            btt.normal)        }        btn.systemFontOfSize(16 * WIDTH)        btn.normal)        self.collectionVIEw.scrollToItemAtIndexPath(NSIndexPath.init(forItem: btn.tag,inSection: 0),atScrollposition: .None,animated: true)        UIVIEw.animateWithDuration(0.3,animations: { () -> VoID in            self.lineVIEw.frame = CGRectMake(15 * WIDTH + (UIScreen.mainScreen().bounds.wIDth / 5.0) * CGfloat (btn.tag),UIScreen.wIDth / 5.0 - 30 * WIDTH,2)            }) {(Bool) -> VoID in            }    }    func initCollectionVIEw() {        let flowLayout = UICollectionVIEwFlowLayout()        flowLayout.scrollDirection = .Horizontal        flowLayout.itemSize = CGSizeMake(UIScreen.wIDth,0)">.height - 88 * HEIGTH)        flowLayout.minimumlinespacing = 0        flowLayout.minimumInteritemSpacing = 0        collectionVIEw = UICollectionVIEw.init(frame: CGRectMake(0,40 * HEIGTH,0)">.height - 88 * HEIGTH),collectionVIEwLayout: flowLayout)        collectionVIEw.delegate = self        collectionVIEw.dataSource = self        collectionVIEw.pagingEnabled = true        collectionVIEw.init(forRow: 2,animated: true)        self.addSubvIEw(collectionVIEw)        collectionVIEw.registerClass(HomeCollectionVIEwCell.classForKeyedArchiver(),forCellWithReuseIDentifIEr: "hCell")        collectionVIEw.registerClass(KindCollectionVIEwCell.registerClass(BrandCollectionVIEwCell.registerClass(SubjectCollectionVIEwCell.registerClass(GiftCollectionVIEwCell.item == 0 {            let cell = collectionVIEw.dequeueReusableCellWithReuseIDentifIEr("kCell",forIndexPath: indexPath) as! KindCollectionVIEwCell            weak var weakSelf = self            cell.initClosure({ (str) -> VoID? in//                let url = "http://mobile.iliangcang.com/goods/goodsShare?a=b&page=1&count=10&coverID=1&cat_code=$&app_key=iPhone&v=3.0.0&sig=97E9576F-B96F-48FD-BE0E-CD84610BC975"                let common = CommonVIEwController()//                common.urlStr = url.stringByReplacingOccurrencesOfString("$",withString: str)                common.urlStr = str                common.hIDesBottombarWhenPushed = true                weakSelf!.pushVIEwController(common,animated: true)                return nil             })            return cell        }else if indexPath.item == 1 {            let cell = collectionVIEw.dequeueReusableCellWithReuseIDentifIEr("bcell",forIndexPath: indexPath) as! BrandCollectionVIEwCell            return cell        }else if indexPath.item == 2 {            let cell = collectionVIEw.dequeueReusableCellWithReuseIDentifIEr("hCell",forIndexPath: indexPath) as! HomeCollectionVIEwCell            cell.myClosure = { (content_ID: String) -> VoID in                let shopVC = ShopVIEwController()                let url = "http://mobile.com/goods/goodsList?a=b&List_ID=$&count=10&page=1&app_key=iPhone&v=3.0.0&sig=97E9576F-B96F-48FD-BE0E-CD84610BC975"                shopVC.pushVIEwController(shopVC,animated: true)            }            return cell        }else if indexPath.item == 3 {            let cell = collectionVIEw.dequeueReusableCellWithReuseIDentifIEr("sCell",forIndexPath: indexPath) as! SubjectCollectionVIEwCell            return cell        }else {            let cell = collectionVIEw.dequeueReusableCellWithReuseIDentifIEr("gCell",forIndexPath: indexPath) as! GiftCollectionVIEwCell            return cell        }    }    func scrollVIEwDIDEndDecelerating(scrollVIEw: UIScrollVIEw) {        for btt in buttonsArray {            btt.normal)        }        UIVIEw.animateWithDuration(0.3) { () -> VoID in        self.wIDth / 5.0) * CGfloat (self.contentOffset.x / (UIScreen.wIDth)),2)        }        let btn = buttonsArray.objectAtIndex(Int(self.x / UIScreen.wIDth))        btn.normal)    }    overrIDe func dIDReceiveMemoryWarning() {        super.dIDReceiveMemoryWarning()        // dispose of any resources that can be recreated.    }}
总结

以上是内存溢出为你收集整理的Swift 类似网易新闻的滑动菜单全部内容,希望文章能够帮你解决Swift 类似网易新闻的滑动菜单所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1062126.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存