斯坦福Developing iOS 8 Apps学习笔记(五)

来源:互联网 发布:北方医疗大数据 编辑:程序博客网 时间:2024/04/30 11:08

Scroll View

ContentSize:CGSize非常重要,如果不设置好ScrollView将没法用

ScrollView的一些基本操作

let upperLeftOfVisible:CGPoint = scrollView.contentOffSetscrollRectToVisible(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.minimumZoomScalescrollView.maximumZoomScale//scrollView's delegatefun viewForZoomingInScrollView(sender:UIScrollView) -> UIView//返回需要缩放的ViewzoomScale:CGFloatsetZoomScale(CGFloat, animated:Bool)zoomToTect(CGRect, animated:Bool)

UIScrollViewDelegate还有ScrollViewDidEndZooming等12个方法,可选


Multithreading

let queue:dispacth_queue_tdispatch_async(queue){}mainQ:dispatch_queue_t = dispatch_get_main_queue()mainQ:NSOperationQueue = NSOperationQueue.mainQueue()//other queues. QOS = Quality of ServiceQOS_CLASS_USER_INTERACTIVE //Quick and high priorityQOS_CLASS_USER_INITIATED //High priority, might take timeQOS_CLASS_UTILITY //Long runningQOS_CLASS_BACKGROUND //user not concerned with this(prefetching, etc.)let qos = Int(上面那些东西.Value)let queue = dispatch_get_global_queue(qos, 0)//Own serial queuelet serialQ = dispatch_queue_create("name", DISPATCH_QUEUE_SERIAL)
//DISPATCH_AFTERlet delayInSeconds = 25.0let 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}
0 0
原创粉丝点击