iOS 高仿手工课(Swift3.0)
2017-07-04 本文已影响81人
蚂蚁牙齿不黑
使用 swift3.0
仿写的一个手工课app,因为手工课官方部分后台接口已经修改,所以在UI展示上与APPStore的上架产品还是有些区别的,仅仅用来学习是一个不错的案例,毕竟内容比较简单,本人是一名小白,所以衷心希望各位大神在代码设计思路上能给出指导意见
开发环境
- swift 3.0
- Xcode8.2.1
- cocoapods 1.1.0.beta.2
- mac os 10.12.2
效果预览
首页
首页.gif home.png市集
fair.png
手工圈
hand.png
我的
我的.gif my.png教程
教程.gif Tutorial.png页面跳转
class KYPageRouter: NSObject {
class func getCurrentNav() -> UINavigationController? {
return getRootVC().selectedViewController as! KYNavgationController
}
class func getRootVC() -> UITabBarController {
return APP.window?.rootViewController as! KYTabBarController
}
class func getCurrentVC() -> UIViewController {
let current = getCurrentNav()
return (current?.viewControllers.last!)!
}
class func openAuthorWebView(webURL : String) {
let animator = XWCoolAnimator.xw_animator(with: .explode)
let webVC = KYWebViewController()
webVC.isPush = false
webVC.webView.webView.loadRequest(URLRequest(url:URL(string:webURL)!))
getCurrentVC().xw_present(webVC, with: animator)
}
}
网络层封装
/// 网络请求回调
typealias NetworkFinished = (_ success: Bool,_ result:JSON?,_ error:NSError?) -> ()
class KYNetWorkTool: NSObject {
static let shared = KYNetWorkTool()
}
// MARK: - 基础请求方法
extension KYNetWorkTool{
/**
GET请求
- parameter urlString: urlString
- parameter parameters: 参数
- parameter finished: 完成回调
*/
func get(_ urlString : String,parameters : [String : Any],finished:@escaping NetworkFinished) {
UIApplication.shared.isNetworkActivityIndicatorVisible = true
Alamofire.request(urlString, method: .get, parameters: parameters, headers: nil).responseJSON { (response) in
self.handle(response: response, finished: finished)
}
}
/**
POST请求
- parameter urlString: urlString
- parameter parameters: 参数
- parameter finished: 完成回调
*/
func post(_ urlString: String, parameters: [String : Any]?, finished: @escaping NetworkFinished) {
UIApplication.shared.isNetworkActivityIndicatorVisible = true
Alamofire.request(urlString, method: .post, parameters: parameters, headers: nil).responseJSON { (response) in
self.handle(response: response, finished: finished)
}
}
/// 处理响应结果
/// - response: 响应对象
/// - finished: 完成回调
fileprivate func handle(response : DataResponse<Any>,finished:@escaping NetworkFinished)
{
UIApplication.shared.isNetworkActivityIndicatorVisible = false
switch response.result
{
case .success(let value):
let json = JSON(value)
finished(true, json, nil)
case .failure(let error):
KYProgressHUD.showErrorWithStatus("失败了,赶紧跑")
finished(false,nil,error as NSError?)
}
}
}
源码地址:KYHandMade