學習iOS開發的第19天

2021-06-21 07:39:20 字數 2036 閱讀 3500

學了一下手勢識別器的運用。下面簡單地演示一下。

手勢包括輕擊、捏合、平移、輕掃、旋轉、長按等。它們分別由相應類來實現。依次為uitapgesturerecognizer、uipinchgesturerecognizer、uipangesturerecognizer、uiswipegesturerecognizer、uirotationgesturerecognizer、uilongpressgesturerecognizer。它們都繼承於uigesturerecognizer類。建立這些類的例項來獲取響應的手勢事件並會繫結制定的方法,手勢會觸發相應的方法。建立好手勢識別器後,可以將手勢識別器新增到view上面。

新建乙個專案,然後建立乙個繼承於uiviewcontroller的檢視控制器,在裡面分別建立那幾個手勢識別器。手勢識別器也有很多屬性可以設定,有興趣者可以深入研究下。

//輕擊識別器

uitapgesturerecognizer *tap = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(tap)];

[self.view addgesturerecognizer:tap];

//捏合

uipinchgesturerecognizer *pinch = [[uipinchgesturerecognizer alloc] initwithtarget:self action:@selector(pinch)];

[self.view addgesturerecognizer:pinch];

//平移

uipangesturerecognizer *pan = [[uipangesturerecognizer alloc] initwithtarget:self action:@selector(pan)];

[self.view addgesturerecognizer:pan];

//輕掃

uiswipegesturerecognizer *swipe = [[uiswipegesturerecognizer alloc] initwithtarget:self action:@selector(swipe)];

//設定方向

swipe.direction = uiswipegesturerecognizerdirectiondown;

[self.view addgesturerecognizer:swipe];

//旋轉

uirotationgesturerecognizer *rotation = [[uirotationgesturerecognizer alloc] initwithtarget:self action:@selector(rotation)];

[self.view addgesturerecognizer:rotation];

//長按

uilongpressgesturerecognizer *longpress = [[uilongpressgesturerecognizer alloc] initwithtarget:self action:@selector(longpress)];

//設定長按最小時間

longpress.minimumpressduration = 1;

[self.view addgesturerecognizer:longpress];

下面是各個手勢所觸發的方法。
-(void)tap

-(void)pinch

-(void)pan

-(void)swipe

-(void)rotation

-(void)longpress

最後在應用程式的**類裡建立檢視控制器。

touchviewcontroller *controller = [[touchviewcontroller alloc] init];

self.window.rootviewcontroller = controller;

執行程式,在螢幕上做出各種手勢,會輸出相應手勢的名稱。

學習iOS開發的第16天

今天主要是做專案,所有沒有花多少時間學習新知識。主要看了下訪問相簿的功能。新建乙個專案,然後在專案裡新建乙個檢視控制器mainviewcontroller。在控制器檢視中新增乙個檢視和乙個按鈕。當按下按鈕時,會執行chooseimage方法。void loadview在chooseimage方法中,...

python練習第19天

二叉樹的最大深度 給定乙個二叉樹,找出其最大深度。二叉樹的深度為根節點到最遠葉子節點的最長路徑上的節點數。說明 葉子節點是指沒有子節點的節點。示例 給定二叉樹 3,9,20,null,null,15,7 這個就是通過遞迴 class solution def maxdepth self,root t...

第19天 AWK詳解

awk是一種處理文字檔案的語言,是乙個強大的文字分析工具。舉例 1.所在路徑 root centos7 ll which awk lrwxrwxrwx.1 root root 4 may 10 13 05 usr bin awk gawk 2.基本用法 awk etc fstab 1指的是第幾列。舉...