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

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}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值