{"id":15037320,"url":"https://github.com/zhangyanlf/zhylfweibo","last_synced_at":"2025-04-09T23:24:07.874Z","repository":{"id":201623926,"uuid":"110185147","full_name":"zhangyanlf/ZhylfWeibo","owner":"zhangyanlf","description":"Swift 仿写微博项目","archived":false,"fork":false,"pushed_at":"2018-08-17T07:51:20.000Z","size":7148,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T01:13:09.010Z","etag":null,"topics":["mvvm","optimizing-performance","swift3","swift4","system-framework"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zhangyanlf.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-11-10T01:10:04.000Z","updated_at":"2024-06-15T08:09:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"2bb1eff7-b627-4eca-8bec-e19290e2e107","html_url":"https://github.com/zhangyanlf/ZhylfWeibo","commit_stats":null,"previous_names":["zhangyanlf/zhylfweibo"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhangyanlf%2FZhylfWeibo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhangyanlf%2FZhylfWeibo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhangyanlf%2FZhylfWeibo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhangyanlf%2FZhylfWeibo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zhangyanlf","download_url":"https://codeload.github.com/zhangyanlf/ZhylfWeibo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248127101,"owners_count":21052179,"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":["mvvm","optimizing-performance","swift3","swift4","system-framework"],"created_at":"2024-09-24T20:34:20.594Z","updated_at":"2025-04-09T23:24:07.842Z","avatar_url":"https://github.com/zhangyanlf.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ZhylfWeibo\n\n# 2017-11-15 项目框架搭建完成，小结：\n# ![image](https://github.com/zhangyanlf/ZhylfWeibo/blob/master/ZhylfWeibo/Classes/zhangyanlf/基本架构流程图.png)\n\n# 首页动画效果\n\n#### 旋转图标动画\n```\n private func startAnimation() {\n        let anim = CABasicAnimation(keyPath: \"transform.rotation\")\n        \n        anim.toValue = 2 * Double.pi\n        anim.repeatCount = MAXFLOAT\n        anim.duration = 15\n        //完成之后不删除\n        anim.isRemovedOnCompletion = false\n        \n        //将动画添加到图层\n        iconView.layer.add(anim, forKey: nil)\n        \n    }\n```\n####  anim.isRemovedOnCompletion = false  动画执行完后不删除  不写时会引起动画执行一个周期/界面切换后停止动画效果\n\n\n# 网络小结：\n ![image](https://github.com/zhangyanlf/ZhylfWeibo/blob/master/ZhylfWeibo/Classes/zhangyanlf/网络框架.png)\n \n ##  AFNetworking 封装网络请求\n ```\n ///封装AF 的 Get /Post\n    ///\n    /// - Parameters:\n    ///   - method: GET/POST\n    ///   - URLString: URLString\n    ///   - parameters: 参数字典\n    ///   - completion: 完成回调 json(字典/数组，是否成功)\n    func request(method: ZlHTTPMethod = .GET, URLString: String,parameters:[String:AnyObject]?,completion:@escaping (_ json:AnyObject?,_ isSuccess:Bool)-\u003e()) {\n\n\n        if method == .GET {\n            get(URLString, parameters: parameters, progress: nil, success: { (task, json) in\n                completion(json as AnyObject, true)\n            }, failure: { (task, error) in\n\n                print(\"网络请求错误\\(error)\")\n                completion(nil, false)\n            })\n        }else{\n            post(URLString, parameters: parameters, progress: nil, success: { (_, json) in\n                completion(json as AnyObject, true)\n            }, failure: { (task, error) in\n                print(\"网络请求错误\\(error)\")\n                completion(nil, false)\n            })\n        }\n    }\n ```\n \n ##  Alamofire 封装网络请求\n ```\nenum MethodType {\n    case GET\n    case POST\n}\n\n\nclass ZLNetWorkTools{\n \n   class func requestDate(type: MethodType, urlString: String,paramters :[String: Any]? = nil,finishedCallback:@escaping (_ result: Any)-\u003e()) {\n        \n        //1.自定义类型\n        let method = type == .GET ? HTTPMethod.get : HTTPMethod.post\n        //2.发送网络请求\n        Alamofire.request(urlString, method: method, parameters: paramters).responseJSON { (response) in\n            //3.获取结果\n            guard let result = response.result.value else {\n                print(response.result.error as Any)\n                return\n            }\n            //4.将结果回调\n            finishedCallback(result)\n        }\n    \n    \n    \n    }\n}\n ```\n# 首页cell显示小结：\n\n## cell显示\n ![image](https://github.com/zhangyanlf/ZhylfWeibo/blob/master/ZhylfWeibo/Classes/zhangyanlf/cell.png)\n\n## 被转发Cell：\n ![image](https://github.com/zhangyanlf/ZhylfWeibo/blob/master/ZhylfWeibo/Classes/zhangyanlf/被转发Cell.png)\n \n## 单张图片等比例显示：\n  ![image](https://github.com/zhangyanlf/ZhylfWeibo/blob/master/ZhylfWeibo/Classes/zhangyanlf/单图等比例显示.png)\n \n## 关于表格试图性能优化：\n\n - 缓存行高\n - 尽量少计算， 所有需要的素材提前计算好\n - 控件不要设置圆角半径  图片渲染的属性都要注意\n - 不要动态创建组件  所有需要的控件 都要提前创建好 在现实的时候 根据数据显示/隐藏\n - cell中控件的数量越少越好\n - 要测量 不要猜测\n  ![image](https://github.com/zhangyanlf/ZhylfWeibo/blob/master/ZhylfWeibo/Classes/zhangyanlf/性能优化.png)\n  \n## 缓存行高步骤\n ![image](https://github.com/zhangyanlf/ZhylfWeibo/blob/master/ZhylfWeibo/Classes/zhangyanlf/缓存行高.png)\n \n ### 在Cell存在头像或者图片需要使用圆角功能是，尽量少用layer.cornerRadiusla来设置图片的圆角，这样会大量占用CPU影响tableView的性能，尽可能去使用路径裁切功能设置图片的圆角，代码如下:\n \n ```\n extension UIImage{\n    \n    /// 创建图片，圆角\n    ///\n    /// - Parameters:\n    ///   - size: 尺寸\n    ///   - backColor: 背景色\n    /// - Returns: 裁切后的图像\n    func zl_avatarImage(size:CGSize?,backColor:UIColor = UIColor.white,lineColor:UIColor = UIColor.lightGray) -\u003e UIImage? {\n        var size = size\n        if size == nil {\n            size = self.size\n        }\n        let rect  = CGRect(origin: CGPoint(), size: size!)\n        \n        /*\n         1\u003esize\n         2\u003e不透明 (混合) png图片支持透明 jpg 图形不支持透明\n         3\u003e屏幕分辨率 如果不指定，默认使用1.0的分辨率（图片质量不好）\n         指定0，会选择当前设备屏幕的分辨率\n         */\n        UIGraphicsBeginImageContextWithOptions(rect.size, true, 0)\n        \n        // 圆角\n        // （0） 背景填充\n        backColor.setFill()\n        UIRectFill(rect)\n        // （1） 原型路径\n        let path = UIBezierPath(ovalIn: rect)\n        // （2） 路径裁切\n        path.addClip()\n        // 2 绘图\n        draw(in: rect)\n\n        // 绘制内切原型\n        let ovaPath = UIBezierPath(ovalIn: rect)\n        \n        lineColor.setStroke()\n        \n        ovaPath.lineWidth = 2\n        \n        ovaPath.stroke()\n        \n        // 3 取得新的图像\n        let result = UIGraphicsGetImageFromCurrentImageContext()\n        // 4 关闭上下文\n        UIGraphicsEndImageContext()\n        // 5 返回结果\n        return result\n        \n    }\n    \n}\n\n ```\n\n\n \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhangyanlf%2Fzhylfweibo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzhangyanlf%2Fzhylfweibo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhangyanlf%2Fzhylfweibo/lists"}