iOS9 3DTouch、ShortcutItem、Peek And Pop
2015-11-03 19:56
218 查看
3DTouch
UITouch类里API的变化
iOS9中添加的属性
altitudeAngle当笔平行于平面时,该值为0
当笔垂直于平面时,该值为Pi / 2
estimatedProperties
当前触摸对象估计的触摸特性
返回值是UITouchPropertyies
updatedProperties
当前触摸对象已经更新的触摸特性
返回值是UITouchPropertyies
estimationUpdateIndex
当每个触摸对象的触摸特性发生变化时,该值将会单独增加
返回值是NSNumber
iOS9中添加的方法
PreciseLocationInView:当前触摸对象的坐标
PrecisePreviousLocationInView:
当前触摸对象的前置坐标
azimuthAngleInview:
沿着x轴正向的方位角
当与x轴正向方向相同时,该值为0
当view参数为nil时,默认为keyWindow
azimuthUnitVectorInView:
当前触摸对象的方向上的单位向量
当view参数为nil时,默认为keyWindow
UIForceTouchCapability
UIForceTouchCapabilityUnknown不能确定是否支持压力感应
UIForceTouchCapabilityUnavailable
不能支持压力感应
UIForceTouchCapabilityAvailable
可以支持压力感应
UITouchType
UITouchTypeDirect垂直的触摸类型
UITouchTypeIndirect
非初值的触摸类型
UITouchTypeStylus
水平的触摸类型
UITouchProperties
UITouchPropertyForce
ShortcutItem
静态方式
打开Info.plist文件在对应UIApplicationShortcutItems关键字下添加item
动态方式
修改当前应用程序的某个shortcutItem
<code class="language-Objctive-C hljs objectivec has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"> <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//获取第0个shortcutItem </span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">id</span> oldItem = [existingShortcutItems objectAtIndex: <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>]; <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//将旧的shortcutItem改变为可修改类型shortcutItem </span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">id</span> mutableItem = [oldItem mutableCopy]; <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//修改shortcutItem的显示标题 </span> [mutableItem setLocalizedTitle: @<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Click Lewis"</span>];</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li></ul>
获取当前应用程序的shortcutItems
<code class="language-Objctive-C hljs objectivec has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"> <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//获取当前应用程序对象 </span> <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">UIApplication</span> *app = [<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">UIApplication</span> sharedApplication]; <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//获取一个应用程序对象的shortcutItem列表 </span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">id</span> existingShortcutItems = [app shortcutItems];</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li></ul>
重置当前应用程序的shortcutItems
<code class="language-Objctive-C hljs objectivec has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"> <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//根据旧的shortcutItems生成可变shortcutItems数组 </span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">id</span> updatedShortcutItems = [existingShortcutItems mutableCopy]; <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//修改可变shortcutItems数组中对应index下的元素为新的shortcutItem </span> [updatedShortcutItems replaceObjectAtIndex: <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> withObject: mutableItem]; <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//修改应用程序对象的shortcutItems为新的数组 </span> [app setShortcutItems: updatedShortcutItems];</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li></ul>
创建一个新的UIApplicationShortcutItem
初始化函数-initWithType:localizedTitle:localizedSubtitle:icon:userInfo:
-initWithType:localizedTitle:
属性
localizedTitle:NSString
-localizedSubtitle:NSString
-type:NSString
-icon:UIApplicationShortcutIcon
-userInfo:NSDictionary
只有只读特性,想要进行修改时,需要通过mutableCopy方法转变为
NSMutableApplicationShortcutItem
创建一个新的Item图标
初始化函数+iconWithType:
+iconWithTemplateImageName:
+iconWithContact:
当程序启动时
判断launchOptions字典内的UIApplicationLaunchOptionsShortcutItemKey是否为空当不为空时,application:didFinishLaunchWithOptions方法返回false,否则返回true
在application:performActionForShortcutItem:completionHandler方法内处理点击事件
Peek and Pop
注册预览功能的代理对象和源视图
代理对象需要接受UIViewControllerPreviewingDelegate协议
<code class="language-Objctive-C hljs css has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"> <span class="hljs-at_rule" style="box-sizing: border-box;">@<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">interface</span> RootVC<UIViewControllerPreviewingDelegate>
</span>{}
<span class="hljs-at_rule" style="box-sizing: border-box;">@<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">end</span></span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li></ul>
代理对象实现协议内的Peek和Pop方法
<code class="language-Objctive-C hljs objectivec has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"> <span class="hljs-class" style="box-sizing: border-box;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">@implementation</span> <span class="hljs-title" style="box-sizing: border-box; color: rgb(102, 0, 102);">RootVC</span> </span> - (<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">UIViewController</span> *)previewingContext:(<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">id</span><UIViewControllerPreviewing>)context viewControllerForLocation:(<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">CGPoint</span>) point { <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">UIViewController</span> *childVC = [[<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">UIViewController</span> alloc] init]; childVC<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">.preferredContentSize</span> = CGSizeMake(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0.0</span>f,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">300</span>f); <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">CGRect</span> rect = CGRectMake(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10</span>, point<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">.y</span> - <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10</span>, <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">self</span><span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">.view</span><span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">.frame</span><span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">.size</span><span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">.width</span> - <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">20</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">20</span>); context<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">.sourceRect</span> = rect; <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">return</span> childVC; } - (<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">void</span>)previewContext:(<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">id</span><UIViewControllerPreviewing>)context commitViewController:(<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">UIViewController</span>*)vc { [<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">self</span> showViewController:vc sender:<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">self</span>]; } <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">@end</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li></li></ul>
注册方法声明在UIViewController类内
[self registerForPreviewingWithDelegate:self sourceView:self.view];
相关文章推荐
- iOS(8)iOS中几种数据持久化方案:我要永远地记住你!
- SDWebImage的使用
- IOS 下载、查询等
- iOS开发 实现QQ第三方登录
- iOS 得到当前时间之前和之后N天的日期
- 开源 iOS 项目分类索引大全
- iOS开发中如何隐藏导航栏下的线条
- iOS提交被拒
- 一个iOS应用开发背后的流程
- IOS开发技巧--模拟器 cannot run 项目.
- FFmpeg在iOS上完美编译
- iOS推送证书的生成
- 绘图与动画之使用自定义属性与Quartz实现扇形加载动画
- IOS代码添加控件,控件移动,放大,缩小,旋转
- nagios详细讲解
- iOS沙盒机制和文件读写
- iOS沙盒机制和文件读写
- iOS Xcode, 解决“Could not insert new outlet connection”的问题。(我使用第二种方法成功了)
- 白盒1:iOS静态代码扫描
- 制作iOS Ad-Hoc测试应用