{"id":22433618,"url":"https://github.com/gavinning/flexview","last_synced_at":"2025-03-27T07:45:49.733Z","repository":{"id":56911403,"uuid":"104703677","full_name":"gavinning/FlexView","owner":"gavinning","description":"简单的盒模型，类似HTML的Flexbox","archived":false,"fork":false,"pushed_at":"2018-04-07T13:27:50.000Z","size":63886,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-03T15:16:22.356Z","etag":null,"topics":["flex","flexbox","flexview","swift"],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gavinning.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-25T04:36:20.000Z","updated_at":"2018-04-07T13:27:13.000Z","dependencies_parsed_at":"2022-08-21T03:20:13.153Z","dependency_job_id":null,"html_url":"https://github.com/gavinning/FlexView","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gavinning%2FFlexView","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gavinning%2FFlexView/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gavinning%2FFlexView/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gavinning%2FFlexView/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gavinning","download_url":"https://codeload.github.com/gavinning/FlexView/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245806390,"owners_count":20675296,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["flex","flexbox","flexview","swift"],"created_at":"2024-12-05T22:15:28.089Z","updated_at":"2025-03-27T07:45:49.705Z","avatar_url":"https://github.com/gavinning.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"FlexView\n---\n简单的盒模型，类似HTML的Flexbox，完整功能还在实现中...  \n适用一些常规布局场景，自动排序，自动间隔，进出场动画，可选纵横\n\n### Install\n```sh\npod install FlexView\n```\n\n### Requirements\n* iOS 10.0+\n* Swift 4.0+\n\n### Usage\n\n```swift\nlet flex = FlexView(frame: CGRect(x: 0, y: 0, width: 320, height: 568))\nlet title = UILabel(frame: CGRect(x: 0, y: 0, width: 320, height: 60))\nlet image = UIImageView(UIImage(named: \"001\"))\n\ntitle.text = \"这是一个标题\"\nimage.frame.size = CGSize(width: 320, height: 320)\n\nflex.addSubview(title)\nflex.addSubview(image)\n```\n\n```swift\n// 盒子子视图排列方向 默认为垂直排列\nflex.axis = .vertical\n// 可选水平排列\nflex.axis = .horizontal\n\n// 子视图之间间距，默认值为0\n// 如果要单独为某个子视图设置间距，直接改变该视图的x,y轴数值即可\nflex.spacing = 0\n\n// 盒子空间占用情况，只读属性\nflex.usedSpace\n```\n\n**删除子视图时更新FlexView** \n```swift\n\nlet flex = FlexView()\nlet btn = UIButton\n\nbtn.addTarget(self, action: #selector(btnClicked(_:)), for: .touchUpInside)\n\n// This in ViewController\n@objc func btnClicked(_ sender: UIButton) {\n\tif let superview = sender.superview as? FlexView {\n\t\t// 使用FlexView的删除方法 removeSubview\n\t\t// 不要使用sender.removeFromSuperview()\n        superview.removeSubview(sender)\n        // 更新contentSize用此方法\n        superview.contentSizeToFit(animated: true)\n        // 更新size用此方法\n        superview.sizeToFit(animated: true)\n\n        // sizeToFit的resize属性默认根据axis的值决定，也可以手动指定\n        // 例如 只更新width\n        superview.sizeToFit(by: .width)\n        // 例如 只更新height\n        superview.sizeToFit(by: .height)\n        // 例如 宽高全部更新\n        superview.sizeToFit(by: .both)\n        // contentSizeToFit使用方法同上\n    }\n}\n```\n\n**添加动画和删除动画**\n```swift\n// 重写可选动画方法 默认为false\nflex.addSubview(_ view: UIView, animated: Bool)\nflex.removeSubview(_ view: UIView, animated: Bool)\nflex.insertSubview(_ view: UIView, at index: Int, animated: Bool)\n```\n  \n\nChangelog\n---\n**v0.3.1**  \n1.修正``addSubview`` ``insertSubview`` Fade动画造成的子视图``alpha``属性失效的问题  \n  \n**v0.3.0**  \n1.重写``sizeToFit``方法用于重设FlexView所占空间  \n2.新增``contentSizeToFit``方法用于重设FlexView滚动区域  \n3.新增``removeSubview``方法，用于删除子视图;  不要直接用``item.removeFromSuperView``，因为FlexView无法跟踪子视图的自我删除操作  \n4.重写``addSubview`` ``insertSubview`` 添加可选动画参数，默认为``false``  \n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgavinning%2Fflexview","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgavinning%2Fflexview","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgavinning%2Fflexview/lists"}