自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

iOS 手勢之左右滑動

移動開發(fā) iOS
本文作者為各位網(wǎng)友朋友們列出了一個iOS開發(fā)中左右滑動手勢的應(yīng)用例子代碼,代碼很實用簡練,可以供各位網(wǎng)友參考學(xué)習之用。

今天想找些關(guān)于ios手勢的資料, 結(jié)果看了幾個都跑不起來, 后來東找找, 西找找終于可以弄了個跑起來的例子.......

下面例子主要做個左右滑動手勢.

1. 先創(chuàng)建一個SingleView的項目.

2. 然后在主界面上放一個Label, 主要用于測試滑動是否起作用.

3. 給label增加一個Outlet. 取名為 "swipeLabel"

4. 在"ViewController.h"中增加兩個手勢property.

  1. @property (nonatomic, strong) UISwipeGestureRecognizer *leftSwipeGestureRecognizer; 
  2. @property (nonatomic, strong) UISwipeGestureRecognizer *rightSwipeGestureRecognizer; 

并synthesize到"ViewController.m"文件中.

5.在"ViewController.m"文件中的"ViewDidLoad"方法中增加如下代碼:

  1. self.leftSwipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipes:)];  
  2.         self.rightSwipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipes:)];  
  3.         self.leftSwipeGestureRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;  
  4.         self.rightSwipeGestureRecognizer.direction = UISwipeGestureRecognizerDirectionRight;  
  5.         [self.view addGestureRecognizer:self.leftSwipeGestureRecognizer];  
  6.         [self.view addGestureRecognizer:self.rightSwipeGestureRecognizer];  

6.并在"ViewController.m"中增加如下方法;

  1. - (void)handleSwipes:(UISwipeGestureRecognizer *)sender 
  2.     { 
  3.         if (sender.direction == UISwipeGestureRecognizerDirectionLeft) { 
  4.             CGPoint labelPosition = CGPointMake(self.swipeLabel.frame.origin.x - 100.0, self.swipeLabel.frame.origin.y); 
  5.             self.swipeLabel.frame = CGRectMake( labelPosition.x , labelPosition.y , self.swipeLabel.frame.size.width, self.swipeLabel.frame.size.height); 
  6.             self.swipeLabel.text = @"尼瑪?shù)? 你在往左邊跑啊...."
  7.         } 
  8.         if (sender.direction == UISwipeGestureRecognizerDirectionRight) { 
  9.             CGPoint labelPosition = CGPointMake(self.swipeLabel.frame.origin.x + 100.0, self.swipeLabel.frame.origin.y); 
  10.             self.swipeLabel.frame = CGRectMake( labelPosition.x , labelPosition.y , self.swipeLabel.frame.size.width, self.swipeLabel.frame.size.height); 
  11.             self.swipeLabel.text = @"尼瑪?shù)? 你在往右邊跑啊...."
  12.         } 
  13.     } 

7. 保存, 編譯, 運行....

責任編輯:閆佳明 來源: oschina
相關(guān)推薦

2015-02-28 15:55:32

手勢gesture過渡

2010-01-28 14:57:36

Android滑動手勢

2015-02-12 13:08:42

左右滑動PagerAdapte分頁

2021-05-29 20:47:00

微軟Windows 10Windows

2011-06-28 09:53:43

iPhone諾基亞N9

2014-10-09 10:42:48

iOS手勢識別

2012-12-24 08:54:47

iOSUnity3D

2013-09-23 09:54:28

2017-10-10 15:14:23

BUGiOS 11蘋果

2015-07-22 10:34:59

手勢密碼源碼

2024-06-21 08:27:21

ViewViewGroup參數(shù)

2019-04-16 09:47:42

iOS應(yīng)用系統(tǒng)

2014-12-31 16:48:43

Touch touchevent多點觸摸

2020-04-24 16:08:12

Android 11新版本功能

2015-01-22 16:04:06

iPhone

2011-03-28 14:04:10

SQL左連接右連接

2021-05-20 09:00:27

SwiftUI Swift TapGesture

2013-07-18 18:14:26

UITableViewiOS長按手勢UILongPress

2022-05-17 12:25:59

物聯(lián)網(wǎng)智能建筑樓宇自控

2013-05-14 11:18:24

AIR AndroidSwipe手勢
點贊
收藏

51CTO技術(shù)棧公眾號