Cocoa 框架iOS CocoaiOS开发

iOS 高仿手工课(Swift3.0)

2017-07-04  本文已影响81人  蚂蚁牙齿不黑

使用 swift3.0 仿写的一个手工课app,因为手工课官方部分后台接口已经修改,所以在UI展示上与APPStore的上架产品还是有些区别的,仅仅用来学习是一个不错的案例,毕竟内容比较简单,本人是一名小白,所以衷心希望各位大神在代码设计思路上能给出指导意见

开发环境

OC版本请戳这里

效果预览

首页

首页.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

上一篇下一篇

猜你喜欢

热点阅读