最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

IOS  手勢(shì)操作詳解及實(shí)例總結(jié)篇

 更新時(shí)間:2017年01月08日 14:31:18   作者:gccll  
這篇文章主要介紹了IOS 手勢(shì)操作詳解及實(shí)例總結(jié)篇的相關(guān)資料,需要的朋友可以參考下

iOS手勢(shì)操作總結(jié)

手勢(shì)操作種類(lèi)

  • UITapGestureRecognizer: 敲擊,點(diǎn)擊
  • UILongPressGestureRecognizer: 長(zhǎng)按
  • UIPinchGestureRecognizer: 縮放
  • UIRotationGestureRecognizer: 旋轉(zhuǎn)
  • UISwipeGestureRecongizer: 輕掃
  • UIPanGestureRecognizer: 拖拽

手勢(shì)操作的代理方法(UIGestureRecognizerDelegate)

手勢(shì)可能發(fā)生的條件,返回NO可以阻止此手勢(shì)的發(fā)生或者此手勢(shì)不產(chǎn)生任何效果

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer;

是否允許多個(gè)手勢(shì)同時(shí)發(fā)生

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)
gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:
(UIGestureRecognizer *)otherGestureRecognizer;

UITapGestureRecognier敲擊,點(diǎn)擊手勢(shì)

  • 設(shè)置屬性numberOfTapsRequired可以指定需要幾根手指才能觸發(fā)事件
  • numberOfTouchesRequired:可以設(shè)置需要敲擊幾次觸發(fā)事件
 UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];

  // 設(shè)置代理
  tap.delegate = self;

  // 設(shè)置點(diǎn)擊次數(shù)觸發(fā)手勢(shì)事件
  tap.numberOfTapsRequired = 1;

  // 設(shè)置需要點(diǎn)擊的手指數(shù)
  tap.numberOfTouchesRequired = 1;

  [self.image addGestureRecognizer:tap];

UILongPressGestureRecongnizer長(zhǎng)按

  • minimumPressDuration設(shè)置長(zhǎng)按的最小間隔時(shí)間,也就是說(shuō)按下開(kāi)始和手指離開(kāi)時(shí)的中間間隔,如果小于這個(gè)值則不會(huì)被認(rèn)為是長(zhǎng)按操作
  • allowableMovement:長(zhǎng)按過(guò)程中是否允許移動(dòng)
  UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];

  // 代理
  longPress.delegate = self;

  // 設(shè)置最小間隔時(shí)間, 手指按下與離開(kāi)間隔時(shí)間
  longPress.minimumPressDuration = 1.0;

  // 按下過(guò)程中允許移動(dòng)的像素
  longPress.allowableMovement = 30;

  [self.image addGestureRecognizer:longPress];

UIPinchGestureRecognizer縮放手勢(shì)

scale: 設(shè)置縮放比例,相對(duì)于原來(lái)大小

 UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinch:)];

  // 代理
  pinch.delegate = self;

  // 設(shè)置縮放比例
  pinch.scale = 1.2;

  [self.image addGestureRecognizer:pinch];

UIRotationGestureRecognizer旋轉(zhuǎn)手勢(shì)

rotation: 旋轉(zhuǎn)弧度,要保證每次都在上一次位置開(kāi)始旋轉(zhuǎn),而不是回歸初始位置,必須要在動(dòng)作方法里將此值清零

- (void)setupRotation
{
  UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotation:)];

  // 設(shè)置代理
  rotation.delegate = self;

  [self.image addGestureRecognizer:rotation];
}

- (void)rotation:(UIRotationGestureRecognizer *)rotation
{
  // 旋轉(zhuǎn)角度
  CGFloat radian = rotation.rotation;

  self.image.transform = CGAffineTransformRotate(self.image.transform, radian);

  // 復(fù)位,保證每次都是在上一次位置開(kāi)始轉(zhuǎn),而不是每次都回歸初始位置再轉(zhuǎn)
  rotation.rotation = 0;
}

UISwipeGestureRecognizer輕掃, 手指按下然后在屏幕上滑動(dòng)

輕掃分四個(gè)方向(上下左右),并且如果要在一個(gè)控件上同時(shí)添加一個(gè)以上的輕掃動(dòng)作,必須對(duì)每個(gè)動(dòng)作添加一個(gè)對(duì)象。也就是說(shuō)每個(gè)方向的動(dòng)作對(duì)應(yīng)一個(gè)對(duì)象。

direction: 指定輕掃動(dòng)作的方向

typedef NS_OPTIONS(NSUInteger, UISwipeGestureRecognizerDirection) {
  UISwipeGestureRecognizerDirectionRight = 1 << 0, // 從左向右
  UISwipeGestureRecognizerDirectionLeft = 1 << 1, // 從右向左
  UISwipeGestureRecognizerDirectionUp  = 1 << 2, // 從下往上
  UISwipeGestureRecognizerDirectionDown = 1 << 3 // 從上往下
};
 UISwipeGestureRecognizer *swipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipe:)];

  // 設(shè)置代理
  swipeUp.delegate = self;

  // 修改方向, 從下往上
  swipeUp.direction = UISwipeGestureRecognizerDirectionUp;

  [self.image addGestureRecognizer:swipeUp];

  // 添加其他方向手勢(shì)
  UISwipeGestureRecognizer *swipeDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipe:)];

  // 修改方向, 從下往上
  swipeDown.direction = UISwipeGestureRecognizerDirectionDown;

  [self.image addGestureRecognizer:swipeDown];

UIPanGestureRecognizer拖拽,按下拖動(dòng)控件操作

注意點(diǎn):手勢(shì)的觸摸點(diǎn)locationInView和手勢(shì)的移動(dòng)點(diǎn)translationInView是不一樣的,前者是用locationInView取得是指手指在當(dāng)前控件中的坐標(biāo),后者表示相對(duì)于父view的rect

  UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];

  // 設(shè)置代理
  pan.delegate = self;

  [self.image addGestureRecognizer:pan];

  // 手勢(shì)的觸摸點(diǎn)
  // CGPoint p = [pan locationInView:self.image];

  // 手勢(shì)的移動(dòng)點(diǎn)(每次移動(dòng)的位移點(diǎn))
  CGPoint transP = [pan translationInView:self.image];

  NSLog(@"%f, %f", transP.x, transP.y);

  self.image.transform = CGAffineTransformTranslate(self.image.transform, transP.x, transP.y);

  // 復(fù)位
  [pan setTranslation:CGPointZero inView:self.image];



感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

相關(guān)文章

最新評(píng)論

报价| 青田县| 讷河市| 杂多县| 宁化县| 铜梁县| 舞钢市| 南雄市| 常德市| 重庆市| 宁陕县| 思南县| 宜丰县| 七台河市| 孟津县| 枝江市| 浏阳市| 彭泽县| 兴安县| 平湖市| 彰武县| 沙田区| 桑植县| 安国市| 梅河口市| 高淳县| 旺苍县| 南木林县| 平谷区| 南京市| 桓台县| 石河子市| 贵阳市| 汤原县| 神池县| 抚顺市| 抚顺县| 漠河县| 广平县| 东阳市| 全椒县|