斯坦福Developing iOS 8 Apps学习笔记(二)
来源:互联网 发布:淘宝飞利浦官方旗舰店 编辑:程序博客网 时间:2024/05/18 03:15
一些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思想的使用方法
- Create a delegation protocol(defines what the View wants the Controller to take care of)
- Create a delegate property in the View whose type is that delegation protocol
- Use the delegation property in the View to get/do
- Controller declares that it implements the protocol things it can’t own or control
- 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
0 0
- 斯坦福Developing iOS 8 Apps学习笔记(二)
- 斯坦福Developing iOS 8 Apps学习笔记(一)
- 斯坦福Developing iOS 8 Apps学习笔记(三)
- 斯坦福Developing iOS 8 Apps学习笔记(四)
- 斯坦福Developing iOS 8 Apps学习笔记(五)
- 斯坦福Developing iOS 8 Apps学习笔记(六)
- 斯坦福Developing iOS 8 Apps学习笔记(七)
- 《Start Developing iOS Apps Today》学习笔记(二)应用实现过程
- Developing iOS 8 Apps with Swift 学习笔记
- 《Start Developing iOS Apps Today》学习笔记(三)心得体会
- Start Developing iOS Apps (Swift) 学习笔记 (1)
- Start Developing iOS Apps (Swift) 学习笔记 (2)
- 《Start Developing iOS Apps Today》学习笔记(一)部分翻译
- Developing iOS 8 Apps with Swift Lesson 11学习
- 斯坦福机器学习笔记(二)
- Start Developing iOS Apps Today
- Start Developing iOS Apps Today
- Start Developing iOS Apps Today
- 正则表达式
- 小游戏设计理念
- android02-数据存储和界面展示
- Android Api Demos登顶之路(六十四)Content-->External Storage
- Hanoi塔问题(递归解决)
- 斯坦福Developing iOS 8 Apps学习笔记(二)
- leetcode RelateArray
- Commando War(UVa 11729)
- 华为OJ平台试题 —— 整数排序
- TreeView常用操作 [不断添加]
- 设计一个可玩性与可重复性高的游戏关卡
- 深入讲解Android Property机制
- uva 11504 - Dominos(强联通分量)
- openlayers2 wfs方式加载矢量图层