内射老阿姨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è)
南充市| 永城市| 正镶白旗| 泽州县| 普陀区| 盐边县| 大名县| 鄂州市| 泰来县| 饶阳县| 南雄市| 获嘉县| 锡林浩特市| 康平县| 阳西县| 定西市| 张家港市| 喀什市| 江孜县| 怀宁县| 盐山县| 鸡东县| 平昌县| 浪卡子县| 汾阳市| 虞城县| 揭西县| 吴忠市| 本溪| 罗定市| 贡山| 宁化县| 从江县| 华宁县| 华坪县| 辛集市| 静海县| 西昌市| 潞城市| 崇州市| 德令哈市|