[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:

  1. Call the sharedMenuController class method of UIMenuController to get the global menu-controller instance.

  2. 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.

  3. Call the setMenuVisible:animated: method (with YES for 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的更多相关文章

  1. Text Relatives

    [Text Relatives] With TextKit the resources at your disposal range from framework objects—such as te ...

  2. Open Xml SDK 引文

    什么是Open Xml SDK? 什么是Open Xml? 首先,我们得知道,Open Xml为何物? 我们还是给她起个名字——就叫 “开放Xml”,以方便我们中文的阅读习惯.之所以起开放这个名字,因 ...

  3. JavaEE XML 基础知识

    JavaEE XML 基础知识 @author ixenos 1.    XML开头都需要一个声明 <?和?>表明这是一个处理指令 <?xml version=”1.0” encod ...

  4. freetype之PC机体验

    目录 freetype之PC机体验 引入 中文教程 官方教程 代码结构 字体概念 PC上安装 官方例子 宽字符保存显示中文 坐标框架体系 字符坐标信息获取 title: freetype之PC机体验 ...

  5. 拼接字符串,生成tree格式的JSON数组

    之前做的执法文书的工作,现在需要从C#版本移植到网页版,从Thrift接口获取数据,加载到对应的控件中 之前用的easyui的Tree插件,通过<ul><li><span ...

  6. 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 ...

  7. spider_action

    spider from mobile to mobile to mobile from selenium import webdriver from selenium.webdriver.chrome ...

  8. firstChild.nodeValue

    var ia=document.getElementsByTagName("em");var t=600; for(var ii=0;ii<t;ii++){var it=ia ...

  9. Probabilistic PCA、Kernel PCA以及t-SNE

    Probabilistic PCA 在之前的文章PCA与LDA介绍中介绍了PCA的基本原理,这一部分主要在此基础上进行扩展,在PCA中引入概率的元素,具体思路是对每个数据$\vec{x}_i$,假设$ ...

随机推荐

  1. ambassador 学习九 多ambassador部署说明

    目前官方稳文档没有写,但是demo 里面有,所以就整理出来,其实目前demo里面的 多实例部署用了多个服务的service(使用nodeport 暴露地址,具体使用就是制定ambassador 实例的 ...

  2. Oracle密码中含有特殊字符时exp,imp的使用

    今天通过exp迁移Oracle 数据,由于密码含有很有很多特殊字符,弄了好久,都没成功,后发在网上找到方法. 1 exp用法Linux 下(密码用一对双引号, 整体userid用对单引号括住)exp ...

  3. cocos2dx Scene,Layer,Sprite的理解

    layer,scene,sprite的默认锚点都是0.5,0.5 三者都继承自Node节点,暂时没看出有什么区别,或者下面的话是对的吧. 在cocos2d-x中,一个应用可以有多个scene,但任何时 ...

  4. 一个filebeat实例 设置多topic设置

    方法1:一实例多topic: https://discuss.elastic.co/t/filebeat-5-0-output-to-kafka-multiple-topics/67934 The d ...

  5. zedgraph中禁用鼠标滚轮变焦(禁止画图区域随鼠标滚动改变XY轴,定位)(转)

    禁用鼠标滚轮变焦的zedgraph功能 如果zgc是你ZedGraphControl实例,请使用: zgc.ZoomButtons = MouseButtons.None; zgc.ZoomButto ...

  6. bzoj1013球形空间

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1013 根据距离式子,两个点的话,两边平方再消掉x^2之后有: a1^2 - 2*a1*x1 ...

  7. 【转】Java常量池详解

    今天My partner问我一个让他头疼的Java question,求输出结果: /** * * @author DreamSea 2011-11-19 */ public class Intege ...

  8. C#计数器

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  9. JavaScript(三) - 精简

    javascript 对象 1 什么是对象? 对象只是一种特殊的数据,对象拥有属性和方法. 2 对象有哪些? js中所有的事物都是对象:字符串,数值,数组,函数. js允许自定义对象.提供多个内建对象 ...

  10. 【UVALive】4094 WonderTeam(神结论)

    题目 传送门:QWQ 分析 好神的结论啊 看代码吧(Length只有85) 代码 顺手压了压代码      目前代码长度rk1 vjudge #include <iostream> ?:n ...