内射老阿姨1区2区3区4区_久久精品人人做人人爽电影蜜月_久久国产精品亚洲77777_99精品又大又爽又粗少妇毛片

[IOS]自定義長(zhǎng)觸屏事件

寫(xiě)一個(gè)Demo來(lái)自定義一個(gè)長(zhǎng)觸屏事件,自定義長(zhǎng)按手勢(shì)。

實(shí)現(xiàn)步驟:

1.創(chuàng)建一個(gè)自定義手勢(shì)類,命名為L(zhǎng)ongPressGestureRecognizer,在創(chuàng)建的時(shí)候繼承UIGestureRecognizer

LongPressGestuRecognizer.h:

#import <UIKit/UIKit.h>  @interface LongPressGestureRecognizer : UIGestureRecognizer  @end

LongPressGestuRecognizer.m:


#import "LongPressGestureRecognizer.h" #import <UIKit/UIGestureRecognizerSubclass.h> #import <time.h>  NSInteger timer1; NSInteger timer2; @implementation LongPressGestureRecognizer   -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {     [super touchesBegan:touches withEvent:event];     NSDate *nowDate = [NSDate date];     NSDateFormatter *dateformatter = [[NSDateFormatter alloc] init];     [dateformatter setDateFormat:@"ss"];          timer1 = [[dateformatter stringFromDate:nowDate] integerValue];     [dateformatter release];     NSLog(@"%d",timer1); }  -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {     [super touchesEnded:touches withEvent:event];     NSDate *nowDate = [NSDate date];     NSDateFormatter *dateformatter = [[NSDateFormatter alloc] init];     [dateformatter setDateFormat:@"ss"];          [dateformatter release];     NSLog(@"%d",timer1);          if ((timer2 -timer1) >= 2)     {          self.state = UIGestureRecognizerStateEnded;     }      }  @end

2.修改主ViewController

ViewController.h:

#import <UIKit/UIKit.h>  @interface DXWViewController : UIViewController<UIGestureRecognizerDelegate>  @end

ViewController.m:

#import "DXWViewController.h"  #import "LongPressGestureRecognizer.h"  @interface DXWViewController ()  @end  @implementation DXWViewController  - (void)viewDidLoad {     [super viewDidLoad];               LongPressGestureRecognizer * longPress = [[LongPressGestureRecognizer alloc] initWithTarget:self action:@selector(LongPress:)];     [self.view addGestureRecognizer:longPress]; }  -(void)LongPress:(LongPressGestureRecognizer *)my {     NSLog(@"OK"); }  @end

3.ViewController中的觸屏事件touchesBegan和自定義手勢(shì)中的touchesBegan區(qū)別:                                              

ViewController中的touchesBegan是針對(duì)整個(gè)View而言的,而自定義中的手勢(shì)是要綁定到某個(gè)特定的view,只針對(duì)這個(gè)view才相應(yīng)的手勢(shì)事件



分享題目:[IOS]自定義長(zhǎng)觸屏事件
文章位置:http://www.rwnh.cn/article2/psgeoc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App開(kāi)發(fā)服務(wù)器托管、外貿(mào)網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)公司網(wǎng)站策劃、網(wǎng)站收錄

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

營(yíng)銷(xiāo)型網(wǎng)站建設(shè)
四会市| 东海县| 四会市| 京山县| 武宣县| 陆河县| 红桥区| 汕尾市| 汨罗市| 汉川市| 海门市| 嵊泗县| 丘北县| 望谟县| 华安县| 石嘴山市| 彰武县| 琼结县| 武山县| 义乌市| 旌德县| 乌拉特后旗| 行唐县| 长治市| 黑河市| 寿光市| 台南县| 普陀区| 鸡泽县| 南宁市| 渭源县| 盐源县| 西盟| 伊通| 广安市| 郁南县| 剑阁县| 保亭| 太和县| 昭平县| 奎屯市|