Chapter 13 UIGestureRecognizer and UIMenuController

1. A UIGestureRecognizer intercepts touches that are on their way to being handled by a view. When it recognizes a particular gesture, it sends a message to the object of your choice. There are several types of gesture recognizers built into the SDK.

2. A UIMenuController has a list of UIMenuItem objects and is presented in an existing view. Each item has a title (what shows up in the menu) and an action (the message it sends the first responder of the window).

3. There is only one UIMenuController per application. When you wish to present this instance, you fill it with menu items, give it a rectangle to present from, and set it to be visible.

-(void)tap:(UIGestureRecognizer*)gr

{

NSLog(@"Recognized tap");

CGPoint point = [gr locationInView:self];

self.selectedLine = [self lineAtPoint:point];

if(self.selectedLine)

{

// Make the target of menu item action messages

[self becomeFirstResponder];

// Grab the menu controller

UIMenuController *menu = [UIMenuController sharedMenuController];

// Create a new "delete" UIMenuItem

UIMenuItem *deleteItem = [[UIMenuItem alloc] initWithTitle:@"delete" action:@selector(deleteLine:)];

menu.menuItems = @[deleteItem];

// Tell the menu where it should come from and show it

[menu setTargetRect:CGRectMake(point.x, point.y, 2, 2) inView:self];

[menu setMenuVisible:YES animated:YES];

}

else

{

[[UIMenuController sharedMenuController] setMenuVisible:NO animated:YES];

}

[self setNeedsDisplay];

}

4. For a menu controller to appear, a view that responds to at least one action message in the UIMenuController’s menu items must be the first responder of the window - this is why you sent the message becomeFirstResponder to the view before setting up the menu controller. If you have a custom view class that needs to become the first responder, you must override canBecomeFirstResponder.

-(BOOL)canBecomeFirstResponder

{return YES;}

5. Normally, a gesture recognizer does not share the touches it intercepts. Once it has recognized its gesture, it “eat” that touch, and no other recognizer gets a chance to handle it.

6. gestureRecognizer: shouledRecognizeSimultaneouslyWithGestureRecognizer.  A gesture recognizer will send this message to its delegate when it recognizes its gesture but realizes that another gesture recognizer has recognized its gesture, too. If this method returns YES, the recognizer will share its touches with other gesture recognizers.

7. A pan gesture recognizer supports the changed state. When a finger starts to move, the pan recognizer enters the began state and sends a message to its target. While the finger moves around the screen, the recognizer transitions to the changed state and sends its action message to its target repeatedly. Finally, when the finger leaves the screen, the recognizer’s state is set to ended, and the final message is delivered to the target.

8. Every UIGestureRecognizer has a property cancelsTouchesInView, by default, this property is YES. This means that gesture recognizer will eat any touch it recognizes so that the view will not have a chance to handle it via the traditional UIResponder methods, like touchesBegan:withEvent:. When you set cancelsTouchesInView to NO, touches that the gesture recognizer recognizes also get delivered to the view via the UIResponder methods. This allows both the recognizer and the view’s UIResponder methods to handle the same touches.

9. Overall, there are seven states a recognizer can enter:

UIGestureRecognizerStatePossible

UIGestureRecognizerStateFailed

UIGestureRecognizerStateBegan

UIGestureRecognizerStateCancelled

UIGestureRecognizerStateChanged

UIGestureRecognizerStateRecognized

UIGestureRecognizerStateEnded

Most of the time, a recognizer will stay in the possible state. When a recognizer recognized its gesture, it goes into the began state. If the gesture is something that can continue, like a pan, it will go into and stay in the changed state until it ends. When any of its properties change, it sends another message to its target. When the gesture ends (typically when the user lifts the finger), it endures the ended state.

时间: 2024-10-25 17:41:57

Chapter 13 UIGestureRecognizer and UIMenuController的相关文章

《linux 内核完全剖析》chapter 13 内存管理 (不含swap.c)

内存管理(memory.c 和swap.s 部分) "倒着看" 先看memory management,很明显,前面各种阻力,都是因为涉及内存管理.不先看这个,我估计前面看了也是白看 我估算着理论打基础砸了差不多一个星期的时间在memory management上面了...感觉很有收获,是时候用实践(code)印证理论了! <modern operating system>讲内存管理那一章 http://blog.csdn.net/cinmyheart/article/de

零元学Expression Blend 4 - Chapter 13 用实例了解布局容器系列-「Pathlistbox」I

原文:零元学Expression Blend 4 - Chapter 13 用实例了解布局容器系列-「Pathlistbox」I 本系列将教大家以实做案例认识Blend 4 的布局容器,此章介绍的布局容器是Blend 4 里的-「Pathlistbox」 ? 本系列将教大家以实做案例认识Blend 4 的布局容器,此章介绍的布局容器是Blend 4 里的-「Pathlistbox」 ? 就是要让不会的新手都看的懂! ? <先来了解Pathlistbox的基本功能> 01 开启一个新专案後,在主

Cpp Chapter 13: Class Inheritance Part1

class inheritance lets you derive new classes from old ones, inheriting its properties of the old class, called the base class With inheritance, you can: 1 add functionality to existing classes 2 add the data a class represents 3 modify how a class m

chapter 13面向对象-再次阅读

1.复习一下dir()和__dict__. >>> class C(object): pass >>> c=C() >>> dir(C) ['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_

Head first java chapter 13 运用swing

Thinking in Java Chapter 13

From Thinking in Java 4th Edition String对象是不可变的.String类中每一个看起来会修改String值的方法,实际上都是创建了一个全新的String对象,以包含修改后的字符串内容.而最初的String对象则丝毫未动: import static net.mindview.util.Print.*; public class Immutable { public static String upcase(String s) { return s.toUpp

数据库 chapter 13 数据库技术新发展

第十三章 数据库技术新发展 数据模型是数据库系统的核心和基础. 按照数据模型的发展,数据库技术可相应地分为三个发展阶段: 第一代的网状.层次数据库系统 第二代的关系数据库系统 第三代数据库系统为核心的数据库大家族 第一代的网状.层次数据库系统的特点: 支持三级模式的体系结构 用存取路径来表示数据之间的联系 独立的数据定义语言 导航的数据操纵语言 关系数据库包括以下三部分: 数据结构 关系操作 数据完整性(包括实体完整性.参照完整性以及与应用有关的完整性) 第三代数据库特点: 第三代数据库系统应支

Chapter 13 - Dynamic type and DLR

The content and code of this article is referenced from book Pro C#5.0 and the .NET 4.5 Framework by Apress. The intention of the writing is to review the konwledge and gain better understanding of the .net framework.    1. The role of C# dynamic key

《JavaScript高级程序设计》Chapter 13 事件

小记 JS与HTML之间的交互通过事件实现,事件发生在交互的瞬间,可以使用事件监听器(或者事件处理程序)来预定时间.DOM2事件模块尽量对事件进行规范,然而DOM3又增加了一些额外的处理方式,再加上BOM和浏览器之间的差异性,事件处理有的时候会十分的复杂.但仍然需要了解基本的概念. 导航 事件流的概念 go 事件处理程序(HTML.DOM0.DOM2以及IE的大体运作方式,跨浏览器处理) go 事件对象(event.DOM和IE的差别,跨浏览器处理)go 事件类型(列举各种常用事件类型,了解一些