使用 swift3.0
仿寫的一個手工課app,因為手工課官方部分后臺接口已經(jīng)修改,所以在UI展示上與APPStore的上架產(chǎn)品還是有些區(qū)別的助泽,僅僅用來學(xué)習(xí)是一個不錯的案例,畢竟內(nèi)容比較簡單漾峡,本人是一名小白,所以衷心希望各位大神在代碼設(shè)計思路上能給出指導(dǎo)意見
開發(fā)環(huán)境
- swift 3.0
- Xcode8.2.1
- cocoapods 1.1.0.beta.2
- mac os 10.12.2
效果預(yù)覽
首頁
市集
手工圈
我的
教程
頁面跳轉(zhuǎn)
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)
}
}
網(wǎng)絡(luò)層封裝
/// 網(wǎng)絡(luò)請求回調(diào)
typealias NetworkFinished = (_ success: Bool,_ result:JSON?,_ error:NSError?) -> ()
class KYNetWorkTool: NSObject {
static let shared = KYNetWorkTool()
}
// MARK: - 基礎(chǔ)請求方法
extension KYNetWorkTool{
/**
GET請求
- parameter urlString: urlString
- parameter parameters: 參數(shù)
- parameter finished: 完成回調(diào)
*/
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: 參數(shù)
- parameter finished: 完成回調(diào)
*/
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)
}
}
/// 處理響應(yīng)結(jié)果
/// - response: 響應(yīng)對象
/// - finished: 完成回調(diào)
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