控件
目前为止学的控件有UIlabel、UIProgress、UIImage、UIbutton、UItableView
各个空间的继承关系
UILabel -> UIView ->UIResponder -> NSObject
UIButton -> UIControl ->UIView
UIImagerView -> UIView
UIButton -> UIControl -> UIView //直接设置动作,触发事件
UITableView -> UIScrollView //协议或闭包获取数据
HTTP请求
let path = "[http://divein.club"](http://divein.club")
let url = NSURL(String: path)
let task = NSURLSEssion.sharedSession().dataTaskWithURL
(url!, completionHandle:{
(data, response, error ) in
if error == nil {
if let httpResponse = response as?
NSHTTPURLResponse {
if httpResponse .statusCode == 200
{
if let d = data {
do {
let array = try! NSJSONSerialization.
jsonObjectWithData(d, options: .AllowFragments ) as?
Array<NSDictionary>
}
}
}
}
} )
}
task.resume( )
百分号转义
let p = "[http://divein.club./中国"](http://divein.club./%E4%B8%AD%E5%9B%BD%22) 非法
let origin: NSString = "中国"
let encode = origin.stringByAddingPercentEscape( )
let p = "[http://divein.club/"](http://divein.club/%22) + encode
音频播放
import AVFoundation
let path = "/..../a.mp3"
let url = NSURL(fileWithPath: path)
let player = try! AVAudioPlayer(contentOfURL: url)
player.delegate = self
player.enableRate = true //变速
player.rate = 2 //2倍速度播放
player.volume = 0.3 //音量
player.prepare()
player.play()
player.duration
player.currentTime
AVAudioPlayerDelegate
audioPlayer didFinish...
定时器
timer.invalidata(
) 定时器不用了一定要停掉
####页面跳转
页面:UIViewController或它的子类
弹出新页面:已经弹出的页面.presentViewController(viewCtrl, animate: true, completion: nil)
消失:self.dismissView....