Text Relatives II
[Text Relatives II]
When your app determines that the user has requested the edit menu—which could be the action of making a selection—you should complete the following steps to display the menu:
Call the
sharedMenuControllerclass method ofUIMenuControllerto get the global menu-controller instance.Compute the boundaries of the selection and with the resulting rectangle call the
setTargetRect:inView:method. The edit menu is displayed above or below this rectangle, depending how close the selection is to the top or bottom of the screen.Call the
setMenuVisible:animated:method (withYESfor both arguments) to animate the display of the edit menu above or below the selection.
Displaying the edit menu:
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *theTouch = [touches anyObject];
if ([theTouch tapCount] == && [self becomeFirstResponder]) {
// selection management code goes here...
// bring up edit menu.
UIMenuController *theMenu = [UIMenuController sharedMenuController];
CGRect selectionRect = CGRectMake (currentSelection.x, currentSelection.y, SIDE, SIDE);
[theMenu setTargetRect:selectionRect inView:self];
[theMenu setMenuVisible:YES animated:YES];
}
}
Before the menu is displayed, however, the system sends a canPerformAction:withSender: message to the first responder, which in many cases is the custom view itself.
Conditionally enabling menu commands:
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
BOOL retValue = NO;
ColorTile *theTile = [self colorTileForOrigin:currentSelection];
if (action == @selector(paste:) )
retValue = (theTile == nil) &&
[[UIPasteboard generalPasteboard] containsPasteboardTypes:
[NSArray arrayWithObject:ColorTileUTI]];
else if ( action == @selector(cut:) || action == @selector(copy:) )
retValue = (theTile != nil);
else
retValue = [super canPerformAction:action withSender:sender];
return retValue;
}
Implementing a Change Color menu item:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *theTouch = [touches anyObject];
if ([theTouch tapCount] == ) {
[self becomeFirstResponder];
UIMenuItem *menuItem = [[UIMenuItem alloc] initWithTitle:@"Change Color" action:@selector(changeColor:)];
UIMenuController *menuCont = [UIMenuController sharedMenuController];
[menuCont setTargetRect:self.frame inView:self.superview];
menuCont.arrowDirection = UIMenuControllerArrowLeft;
menuCont.menuItems = [NSArray arrayWithObject:menuItem];
[menuCont setMenuVisible:YES animated:YES];
}
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {}
- (BOOL)canBecomeFirstResponder { return YES; }
- (void)changeColor:(id)sender {
if ([self.viewColor isEqual:[UIColor blackColor]]) {
self.viewColor = [UIColor redColor];
} else {
self.viewColor = [UIColor blackColor];
}
[self setNeedsDisplay];
}
Dismiss the Edit Menu:
[UIMenuController sharedMenuController].menuVisible = YES;
Text Relatives II的更多相关文章
- Text Relatives
[Text Relatives] With TextKit the resources at your disposal range from framework objects—such as te ...
- Open Xml SDK 引文
什么是Open Xml SDK? 什么是Open Xml? 首先,我们得知道,Open Xml为何物? 我们还是给她起个名字——就叫 “开放Xml”,以方便我们中文的阅读习惯.之所以起开放这个名字,因 ...
- JavaEE XML 基础知识
JavaEE XML 基础知识 @author ixenos 1. XML开头都需要一个声明 <?和?>表明这是一个处理指令 <?xml version=”1.0” encod ...
- freetype之PC机体验
目录 freetype之PC机体验 引入 中文教程 官方教程 代码结构 字体概念 PC上安装 官方例子 宽字符保存显示中文 坐标框架体系 字符坐标信息获取 title: freetype之PC机体验 ...
- 拼接字符串,生成tree格式的JSON数组
之前做的执法文书的工作,现在需要从C#版本移植到网页版,从Thrift接口获取数据,加载到对应的控件中 之前用的easyui的Tree插件,通过<ul><li><span ...
- oracle已知会导致错误结果的bug列表(Bug Issues Known to cause Wrong Results)
LAST UPDATE: 1 Dec 15, 2016 APPLIES TO: 1 2 3 4 Oracle Database - Enterprise Edition - Versi ...
- spider_action
spider from mobile to mobile to mobile from selenium import webdriver from selenium.webdriver.chrome ...
- firstChild.nodeValue
var ia=document.getElementsByTagName("em");var t=600; for(var ii=0;ii<t;ii++){var it=ia ...
- Probabilistic PCA、Kernel PCA以及t-SNE
Probabilistic PCA 在之前的文章PCA与LDA介绍中介绍了PCA的基本原理,这一部分主要在此基础上进行扩展,在PCA中引入概率的元素,具体思路是对每个数据$\vec{x}_i$,假设$ ...
随机推荐
- 自定义简单的struts2的s标签
一:自定标签前需要了解的知识: BodyTagSupport类的方法: 编写标签对应的实现类时,需要重载BodyTagSupport类几个方法:doStartTag(), setBodyContent ...
- kudu 虚拟机环境使用
安装 curl -s https://raw.githubusercontent.com/cloudera/kudu-examples/master/demo-vm-setup/bootstrap ...
- UNIX 时间戳 C#
/// 将Unix时间戳转换为DateTime类型时间 /// </summary> /// <param name="d">double 型数字</ ...
- oracle行跟踪(基于行跟踪的ROWDEPENDENCIES ORA_ROWSCN信息)
在Oracle 10g中的引入了ORA_ROWSCN伪列新特性.基于此种伪列所提供的信息,我们可以方便地找出某个数据块或某一个行最近被修改的时间戳.在默认情况下,10g下表会以非行依赖性(NOROWD ...
- redis与lua
内容大纲 redis里使用eval和evalsha redis管理Lua脚本 php里使用redis的lua脚本 在redis里使用lua脚本的好处 1.Lua脚本在Redis中是原子执行的,执行过 ...
- [题解] [NOIP2008] 双栈排序——关系的冲突至图论解法
Problem 题目描述 Tom最近在研究一个有趣的排序问题.如图所示,通过2个栈S1和S2,Tom希望借助以下4种操作实现将输入序列升序排序. 操作a 如果输入序列不为空,将第一个元素压入栈S1 操 ...
- java批量下载,将多文件打包成zip格式下载
现在的需求的: 根据产品族.产品类型,下载该产品族.产品类型下面的pic包: pic包是zip压缩文件: t_product表: 这些包以blob形式存在另一张表中: t_imagefile表: 现在 ...
- unittest框架出报告乱码的问题解决
跟着上面的步骤修改好后,unittest断言写法要写成下面这样才能展示非乱码
- springboot的interceptor(拦截器)的应用
一.SpringMVC 中的Interceptor 拦截器也是相当重要和相当有用的,它的主要作用是拦截用户的请求并进行相应的处理.在web开发中,拦截器是经常用到的功能.它可以帮我们验证是否登陆.预先 ...
- C#中的参数关键字params
class 参数 { public void doSome(string str,params int[] values){ ) { ; i < values.Length; i++) { Co ...