IOS 5.1 使用手势操作

基本操作流程是

1 再对应的viewCtroller写一个对应的手势实现方法。用IBAtion

2 storyboard中在需要使用该手势的地方拖一个对应的手势过去,在把那个手势与IBAtion相连就行了。

3 记得在对应的view那里检查User Interaction Enabled 是否勾上了。

 

一般情况下,一个view不能同时进行多个手势操作,但是打开一个UIGestureRecognizer代理属性后就可以了。

具体方法如下:

  在您view的viewController.h内加入以下代理方法

  @interface:ViewController<UIGestureRecognizerDelegate>

  然后在.m文件内加入

  

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {        
    return YES;
}
这样就能在一个view中同时使用多个gesture了,另外在IOS模拟器中按住option就能缩放了。


如果要定制自己的UIGesture,具体过程如下:

1.new 一个subclass of UIGestureRecognizer。一般里面的instance variable可以有int型点击次数;手势的方向,这个可以typedef enum出来几种;一个当前点的位置表示cgpoint。


2.在.m文件中切记要在文件开头导入 "import <UIKit/UIGestureRecognizerSubclass.h>",否则后面需要设置收拾状态结束会遇到self.state 是一个readonly属性。


3.在.m文件中一般需要以下这四种方法
  - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
  - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
      在这个方法里注意设置动作结束状态;
    
  - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
  - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event

      在以上两个方法里注意设置failed状态,如果还在possible状态的话。 








posted @ 2012-08-16 17:54  sayALittle  阅读(1145)  评论(0编辑  收藏  举报
点击这里给我发消息