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

一些storyboard的trick

  • @IBDesignable 可以在storyboard中预览代码绘图效果(有点tricky,如果画不出来也是有可能的(绘图依赖某些复杂依赖关系))
  • @IBInspectable 让某些变量的设置可以在Storyboard中进行,类似于storyboard中原生的Attribute aspect

Extensions

  • 对于新手来说,Extension主要功能在于
    • 增加某些辅助功能,辅助函数
  • 注意
    • 在extension中overwrite是不行的
    • 定义property只能是computed,不能有storage
  • 对于大神来说Extension是一种架构的方式,具体可在架构书中学习

Protocols and Delegation

Protocol书写中需要注意的地方

protocol SomeProtocol:(class), InheritedProtocol {
    var property:Int {get,set}
    func aMethod(arg1:Double, ...) -> SomeType
    mutating func change()
    init(arg:Type)
}
  • class表示只有类可以遵守的协议
  • property要标明get,set还是get
  • 对于在结构体和枚举中使用的协议,如果要修改property,需要标注 mutating

Delegation思想的使用方法

  1. Create a delegation protocol(defines what the View wants the Controller to take care of)
  2. Create a delegate property in the View whose type is that delegation protocol
  3. Use the delegation property in the View to get/do
  4. Controller declares that it implements the protocol things it can’t own or control
  5. Controllers set self as the delegation of the View

??运算符

expression1 ?? expression2
相当于
if expression1 = nil
return expression2
else
return expression1

Gestures

UIPanGestureRecognizer

  • translationInView(view:UIView) -> CGPoint
  • velocityInView(view:UIView) -> CGPoint
  • setTranslation(translation:CGPoint, inView:UIView)
  • state:UIGestureRecognizerState
    • .Possible
    • .Recognized(discrete)
    • (continues) .Begin .Changed .Ended
    • .Failed
    • .Cancelled(Phone call in)
  • 对于state的处理
switch gesture.state
    case .Changed:fallthrough
    case .Ended:
        let translation = gesture.translationInView(aView)
        //update
        gesture.setTranslation(CGPointZero,inView:aView)
    default:break

UIPinchGestureRecognizer

  • var scale:CGFloat
  • var velocity:CGFloat{get}

UIRotationGestureRecognizer

  • var rotation:CGFloat //in radians
  • var velocity:CGFloat{get} //in radians

UISwipeGestureRecognizer

  • var direction(set when init):UISwipeGestureRecognizerDirection
  • var numberOfTouchesRequired:Int //finger count
  • 观察state .Recognized状态

UITapGestureRecognizer

  • var numberOfTapsRequired:Int //点击次数 If Double,check out .Ended
  • var numberOfTouchesRequired:Int //Finger Count
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值