默认教学计划
947人加入学习
(4人评价)
价格 免费
教学计划
承诺服务

.menuItemSeparatorWidth(4.3),

        .scrollMenuBackgroundColor(UIColor.white),

        .viewBackgroundColor(UIColor(red: 247.0/255.0, green: 247.0/255.0, blue: 247.0/255.0, alpha: 1.0)),

        .bottomMenuHairlineColor(UIColor(red: 20.0/255.0, green: 20.0/255.0, blue: 20.0/255.0, alpha: 0.1)),

        .selectionIndicatorColor(UIColor(red: 18.0/255.0, green: 150.0/255.0, blue: 225.0/255.0, alpha: 1.0)),

        .menuMargin(20.0),

        .menuHeight(40.0),

        .menuItemWidth(100),

        .selectedMenuItemLabelColor(UIColor(red: 18.0/255.0, green: 150.0/255.0, blue: 225.0/255.0, alpha: 1.0)),

        .unselectedMenuItemLabelColor(UIColor(red: 40.0/255.0, green: 40.0/255.0, blue: 40.0/255.0, alpha: 1.0)),

        .menuItemFont(UIFont(name: "HelveticaNeue-Medium", size: 14.0)!),

        // 菜单允许滑动

        .useMenuLikeSegmentedControl(false),

        .menuItemSeparatorRoundEdges(true),

        .selectionIndicatorHeight(2.0),

        .menuItemSeparatorPercentageHeight(0.1)

[展开全文]

网络请求和普通函数的返回值 不能等同

因为网络请求是有延迟的!

extension Category {

  static func request(completion:@escaping([Category]? -> void)){

 // 代码块

provider.request(.category) { (result) in 

   switch result {

   case let .success(moyaResponse):

   let json = try! moyaResponse.mapJSON() as! [String:Any]

if let jsonResponse = CategoryIndexResponse(JSON:json) {

  // 返回值给逃逸闭包

  completion(jsonResponse.categories)

}

}

}

 

}

}

[展开全文]

tableViewCell 内的文本 自适应高度

label文本的行数设为 0 

[展开全文]

点中textField -> 记得拉线设置代理

更新界面都在主线程

Post.submitComment(postId:post.id,name:"布袋",email:"apiapia@163.com",content:commentText) { (finish) in 

if finish {

print ("发布评论成功")

OperationQueue.main.addOperation{
self.showComentBadge(self.post.comment_count + 1)

}

}

}

Editing Did Begin // 开始弹出窗口的时候

@IBAction func editBegin(_ sender:UITextField) {

 

}

@IBAction func editDone (_ sender:UITextField) {

guard let commentText = sender.text else {return}

loadDanmu(postAComment:commentText)

}

Editing Did End // 完成编辑 即键盘收回的时候

 

[展开全文]
布袋 · 2017-07-18 · 3.提交评论 0

弹幕的颜色设置为

clearColor 为透明色

把Attriibuted To Plain

Html 标签过滤

 

extension String {

var html2Attri:NSAttributedString?{

    do{

 try NSAttributedString(data:Data(utf8),options:[NSDocuementTypeDocumentAttribute:NSHtmlTextDocumentType,NSCharacterEncodingDocumentAttributes:String.Encoding.utf8.rawValue],documentAttributes:nil)

}catch{

return nil

}

}

var html2String:String {

 return html2Attri?.string ?? ""

}

}

[展开全文]

Model 的建立

//NetworkService.swfit 发表文章的评论

var pagameters:[String:Any]?{

switch self {

case .category:reutrn nil

case .showCateNewsList(let id):

return ["id":id]

case .submitComment[let postID,let name,let email,let content]:

return ["post_id":postId,"name":name]

}

}

// Post.swift 发表文章的评论

static func submitComment(postId:Int,name:String,completion:@escaping(Bool) ->Void) {

let provider = MoyaProvider<NetworkService>()

 provider.request(.submitComment(postId:postId,name:name,email:email,content:content)){ result in 

switch result {

case let .success(moyaResponse):

let json = try! moyaResponse.mapJSON()! as [String:Any]

if let jsonResponse = SubmitResponse(JSON:json) {

if jsonResponse.stauts == "ok" {

 complection(true)

}else {

complection(false)

}

}

case .failure:

print("网络错误")

complection(nil)

 

}

 

}

}

 

 

 

[展开全文]

弹幕的评论构建 

Storyboard 自定义UIView 高度 44

UITextField 的placeHolder 

 

 

[展开全文]

IQKeyboardManger 导航条消失的问题:

设置self.navigationController?.hidesBarsWhenKeyboardAppears = true
self.navigationController?.hidesBarsOnTap = true 

 

关键:

对服务器返回的评论的一条或多条要进行判断

AppDelegate 

IQKeyboardManger.shared.isEnabled = true

ViewController.swift

webview = WKWebView(frame:frame)
view.insertSubview(webView,at:0)


弹幕 View的Storyboard 加载 方法 
command + 拉线到父视图+ equal height 
右侧栏contraints 

弹幕是多条还是一条

extension UIColor {

static var danmu:[UIColor] {

return [UIColor.blue,UIColor.red]

}

}

// 数组转数组 高阶函数 Map

viewDidLoad {

loadDanmu(comments:post.comments)

}

func loadDamnu(comments:[Comment]? = nil,postAComment:String? = nil) {

if danmuOnOff {

 danmuView.resume()

 if let coments = coments {
// 把评论coments的数组转化为 弹幕danmu的数组

 let danmus:[LeoDanmakuModel] = comments.map {

let model = LeoDanmakuModel.randomDanmku(withColors:UIColor.danmu,maxFontSize:30,minFontSize:15)
model?.text  = $0.content

}

danmuView.addDanmaku(with:danmus)

}

// 单条弹幕

if let comment = postAComment {

let danmuSingle = LeoDanmakuModel.randomDanmku(withColors:UIColor.danmu,maxFontSize:30,minFontSize:15)

model.text = comment

danmuView.addDanmaku(danmuSingle)

}

}else {

danmuView.stop()

}

}

 

[展开全文]

H5 viewport 

www.cnblogs.com/2050/p/3877280.html

<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">

w3cSchool

// 因为内容只有content ,所以要加入Html标签 

var header = "<html><head>"
header = "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0\">"

header += "<style>"
header +="img {width:100%}"  // 对网页的图片自适应手机屏幕宽度
header += "body {font-size:100%}" // 对手机屏模上的字体
header += "</style>"
header += "</head><body>"
var footer = "</body></html>"

 

css优先级 H5课程

作业
1、把content所有的图片(有的图片有自己的样式))换成自适应(网页中字符串中的替换))
2、在TableCell里插入缩略图(从网页content内容里取出其中的一张图片)

 

 

 

[展开全文]

Post.request(id:id) {(posts) in 

if let posts = posts {

// 主线程直接更新

OperationQueue.main.addOperation {

self.newsList = posts
self.tableView.reloadData()

}

}else {

print ("网络错误")

}

}

 

PageMenu 载入不同的ViewController

Cagetory.request {(cates) in 

self.controllers = cates!.map {

 let vc = self.storyboard?.instantiateViewController(withIdentifer:"SBID_NewsList") as! NewsListController 

vc.title = $0.title

vc.parentNavi = self.navigationController
vc.id = $0.id

return vc 

}

}

高级篇  NewsListController:UITableViewController 

tableView.estimatedRowHeight  = 100 
tableView.rowHeight = UITableViewAutomationDimension 

[展开全文]

import Moya

var parameters:[String:Any]?{

switch self {

 case .category:

return nil

case .showCateNewsList(let id):

return ["id":id]

}

}

[展开全文]

导航条

var parentNavigation:UINavigationController?

 

// 返回只一个arrow

override func viewDidLoad(){

navigationItem.backBarButtonItem = UIBarButtonItem(title:"",style:.plain,target:self,action:nil)

}

[展开全文]

第三方 PageMenu 菜单

var controllers:[UIViewController] = []

Category.request {

(cates) in 

self.controllers = cates!.map {

let vc  = self.storyboard?.instantiateViewController(withIdentifier:"SBID_NewsList") as! NewsListController

vc.title = $.title

return vc

}

let param:[CAPSPageMenuOption] = []

let frame = CGRect()

self.pageMenu = CAPSPageMenu(viewControllers:self.controllers,frame:frame,pageMenuOptions:param)

self.view.addSubView(self.pageMenu.view)

}

[展开全文]

// html 5 底部加入评论

var header = "<html>"
header += "<header>"
header += "<style></style>"
header += "</header>"
header += "<body>"
let comment = "<hr> + commmentHtml(comments:post.comments)
var footer = "</body></html>"

webView.loadHtmlString(header + post.content + comment + footer,baseURL:nil)

func commentHtml(commetns:[Comments]{
var results = ""
for comment in comments {
  let params = "\(comment.name!),\(comment.content!)"
 }
return results
}

[展开全文]

badge  第三方
 评论+角标
WZLbadge 

// CGFLOAT_MAX 动画的次数

LeoDanmakukit 添加纯文字弹幕

LLSwitch 有趣的Switch

[展开全文]

wordDpress

[展开全文]
chris · 2017-06-08 · 效果赏析 0

swift 引用javascript

点击评论直接滑动到指定位置  

google : scroll to element

www.bootcdn.cn 引用 jQuery

lazy var wkWebView: WKWebView = {
        var webView = WKWebView(frame: self.view.bounds)
        let url = URL(string: self.urlString)
        webView.load(URLRequest(url: url!))
        
        /*
        var  jsString = "<html><head>"
        jsString += "<script src=\"https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js\"></script>"
        jsString += "<script>"
        jsString += "$(document).ready(function (){"
        jsString += "    $('html, body').animate({"
        jsString += "        scrollTop: $(\".image-package\").offset().top"
        jsString += "    }, 200);"
        jsString += "});"
        jsString += "</script>"
        jsString += "</head>"
        jsString += "<body>"
        jsString += "<div style='height:5800'>aabccc</div>"
        jsString += "<div class=\"image-package\"><img src='https://upload-images.jianshu.io/upload_images/5780217-3a7d8440338047f6.png?imageMogr2/auto-orient/strip|imageView2/2/w/1240' width='\(UIScreen.main.bounds.size.width)'></div>"
        jsString += "</body></html>"
        webView.loadHTMLString(jsString, baseURL: Bundle.main.bundleURL)
        printLog(jsString)
        */
        webView.uiDelegate = self
        webView.navigationDelegate = self
        webView.isUserInteractionEnabled = true
        return webView
    }()

 

    @IBAction func commentTap(_ sender: UIButton) {
       
         let jsString = "document.getElementsByClassName(\"image-package\")[0].style.display = \"none\";"
//        html有引入 min.js 才可以使用,否则使用上方代码
//        jsString += "$(document).ready(function(){"
//        jsString += "$('.image-package').hide();"
//        jsString += "});"
        
        self.wkWebView.evaluateJavaScript(jsString) { (result, error) in
            printLog(jsString)
           
        }
       
   
    }

 

 

[展开全文]

网络封装

Moya

 

Wordpress

[展开全文]
布袋 · 2017-06-05 · 效果赏析 0

授课教师

Swift小菜

课程特色

视频(33)