斯坦福Developing iOS 8 Apps学习笔记(二)
2015-09-11 21:13
375 查看
一些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) -> CGPointvelocityInView(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:CGFloatvar velocity:CGFloat{get}
UIRotationGestureRecognizer
var rotation:CGFloat //in radiansvar velocity:CGFloat{get} //in radians
UISwipeGestureRecognizer
var direction(set when init):UISwipeGestureRecognizerDirectionvar numberOfTouchesRequired:Int //finger count
观察state .Recognized状态
UITapGestureRecognizer
var numberOfTapsRequired:Int //点击次数 If Double,check out .Endedvar numberOfTouchesRequired:Int //Finger Count
相关文章推荐
- Android Api Demos登顶之路(六十四)Content-->External Storage
- SQLite—Android数据库
- Android MVP模式实践
- iOS学习总结----代理协议2
- iOS学习总结----代理协议1
- WebSphere Application Server V8 中的垃圾收集,第 2 部分: 新的平衡垃圾收集选项
- android学习之路——android编程规范
- WebSphere Application Server V8 中的垃圾收集,第 1 部分: 使用分代收集策略作为新的默认策略
- (4.1.35.1) android处理crash程序崩溃异常
- Java 7 在 WebSphere Application Server V8.5 中的安装配置和版本切换
- Android性能优化典范之Profile GPU Rendering
- Android性能优化典范
- Android开发——构建自定义组件
- OC-字符串的运用
- Cocos2dx 3.X jsb加载JavaScript源码文件分析
- IOS IPA打包遇到的问题:code signing is required for product type 'Application' in SDK 'iOS 8.1
- Android的菜单不能显示
- Android应用开发:图形绘制之硬件加速
- AppCoda Beginning IOS8 Programming With Swift
- iOS软件开发 裁剪图片