Scroll View
ContentSize:CGSize非常重要,如果不设置好ScrollView将没法用
ScrollView的一些基本操作
let upperLeftOfVisible:CGPoint = scrollView.contentOffSet
scrollRectToVisible(CGRect, animated:Bool)
还可以设置
- whether scroll is enabled
- locking scroll direction
- style of scroll indications(call flashScrollIndicators when scroll view appear)
- whether the actual content is “inset” from content area(contentInset)
Zooming
注意:Zooming affect contentSize & contentOffSet
scrollView.minimumZoomScale
scrollView.maximumZoomScale
//scrollView's delegate
fun viewForZoomingInScrollView(sender:UIScrollView) -> UIView
//返回需要缩放的View
zoomScale:CGFloat
setZoomScale(CGFloat, animated:Bool)
zoomToTect(CGRect, animated:Bool)
UIScrollViewDelegate还有ScrollViewDidEndZooming等12个方法,可选
Multithreading
let queue:dispacth_queue_t
dispatch_async(queue){
}
mainQ:dispatch_queue_t = dispatch_get_main_queue()
mainQ:NSOperationQueue = NSOperationQueue.mainQueue()
//other queues. QOS = Quality of Service
QOS_CLASS_USER_INTERACTIVE //Quick and high priority
QOS_CLASS_USER_INITIATED //High priority, might take time
QOS_CLASS_UTILITY //Long running
QOS_CLASS_BACKGROUND //user not concerned with this(prefetching, etc.)
let qos = Int(上面那些东西.Value)
let queue = dispatch_get_global_queue(qos, 0)
//Own serial queue
let serialQ = dispatch_queue_create("name", DISPATCH_QUEUE_SERIAL)
//DISPATCH_AFTER
let delayInSeconds = 25.0
let delay = Int64(delayInSeconds * Double(NSEC_PER_MSEC))
let dispatchTime = dispatch_time(DISPATCH_TIME_NOW, delay)
dispatch_after(dispatchTime, dispatch_get_main_queue){
}
GCD还可以做locking, protect critical sections, readers and writers, synchronous dispatch, etc.
Others
- @objc可以定义有可选的Protocol
- imageView.sizeToFit()可以让ImageView大小适合image
- view.window != nil可以说明我们在当前界面上
- 闭包中的引用循环
- 闭包是类的一个变量,闭包调用self.someMethod()
- 解决:
{[unowned self] in}