ios觸屏事件指南
更新時(shí)間:2015年05月27日 11:51:11 投稿:hebedich
這篇文章主要給大家總結(jié)介紹了2種實(shí)現(xiàn)ios觸屏事件的方法,簡(jiǎn)單實(shí)用,有需要的小伙伴可以參考下。
復(fù)制代碼 代碼如下:
//在一個(gè)函數(shù)里面(初始化等)里面添加要識(shí)別觸摸事件的范圍
infoView=[[UIView alloc] initWithFrame:CGRectMake(20, 100,220, 280)];//范圍,出了這個(gè)范圍就檢測(cè)不到觸摸了
infoView.backgroundColor=[UIColor blueColor];
infoView.alpha=0.6;
[self.view addSubview:infoView];
/******************監(jiān)視手勢(shì)控制*****************///有上下左右,我只用到了左右,上下注掉了。
UISwipeGestureRecognizer *recognizer;
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
[infoView addGestureRecognizer:recognizer];
// recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
// [recognizer setDirection:(UISwipeGestureRecognizerDirectionUp)];
// [self.view addGestureRecognizer:recognizer];
// recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
// [recognizer setDirection:(UISwipeGestureRecognizerDirectionDown)];
// [self.view addGestureRecognizer:recognizer];
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];
[infoView addGestureRecognizer:recognizer];
//觸摸事件 的實(shí)現(xiàn)函數(shù)
//滑動(dòng)事件1
-(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer{
//如果往左滑
if(recognizer.direction==UISwipeGestureRecognizerDirectionLeft) {
NSLog(@"****************向左滑****************");
}
//如果往右滑
if(recognizer.direction==UISwipeGestureRecognizerDirectionRight) {
NSLog(@"****************向右滑****************");
}
if (recognizer.direction==UISwipeGestureRecognizerDirectionDown){
NSLog(@"****************向下滑****************");
}
if (recognizer.direction==UISwipeGestureRecognizerDirectionUp){
NSLog(@"****************向上滑****************");
}
}
方法二:
復(fù)制代碼 代碼如下:
GSEventRecord header;
GSHardwareKeyInfo key = {0,0,0,0,1,{'a'},1,{'a'},0,0,0,0};
memset(&header, 0, sizeof(header));
header.type = kGSEventKeyDown;
header.infoSize = sizeof(GSHardwareKeyInfo);
header.timestamp = mach_absolute_time();
struct
{
GSEventRecord header1;
GSHardwareKeyInfo key1;
}fuck = {header, key};
GSSendEvent(&fuck, GSGetPurpleApplicationPort());
GSEventRecord header;
GSHardwareKeyInfo key = {0,0,0,0,1,{'a'},1,{'a'},0,0,0,0};
memset(&header, 0, sizeof(header));
header.type = kGSEventKeyDown;
header.infoSize = sizeof(GSHardwareKeyInfo);
header.timestamp = mach_absolute_time();
struct
{
GSEventRecord header1;
GSHardwareKeyInfo key1;
}fuck = {header, key};
GSSendEvent(&fuck, GSGetPurpleApplicationPort());
以上所述就是本文的全部?jī)?nèi)容了,希望大家能夠喜歡。
您可能感興趣的文章:
- 用iOS代碼獲取APP啟動(dòng)頁(yè)圖片
- IOS中實(shí)現(xiàn)圖片點(diǎn)擊全屏預(yù)覽
- iOS開(kāi)發(fā)中使用屏幕旋轉(zhuǎn)功能的相關(guān)方法
- iOS開(kāi)發(fā)中控制屏幕旋轉(zhuǎn)的編寫(xiě)方法小結(jié)
- iOS開(kāi)發(fā)之使用Storyboard預(yù)覽UI在不同屏幕上的運(yùn)行效果
- 總結(jié)iOS App開(kāi)發(fā)中控制屏幕旋轉(zhuǎn)的幾種方式
- 在iOS開(kāi)發(fā)的Quartz2D使用中實(shí)現(xiàn)圖片剪切和截屏功能
- iOS應(yīng)用開(kāi)發(fā)中使用Auto Layout來(lái)適配不同屏幕尺寸
- iOS程序開(kāi)發(fā)中設(shè)置UITableView的全屏分隔線的方法(不畫(huà)線)
- iOS實(shí)現(xiàn)動(dòng)態(tài)的開(kāi)屏廣告示例代碼
相關(guān)文章
iOS UILabel 設(shè)置內(nèi)容的間距及高度的計(jì)算示例
本篇文章主要介紹了iOS UILabel 設(shè)置內(nèi)容的間距及高度的計(jì)算示例,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-11-11
iOS開(kāi)發(fā)之UITableView左滑刪除等自定義功能
今天來(lái)給大家介紹下iOS開(kāi)發(fā)中UITableView左滑實(shí)現(xiàn)微信中置頂,刪除等功能。對(duì)大家開(kāi)發(fā)iOS具有一定的參考借鑒價(jià)值,有需要的朋友們一起來(lái)看看吧。2016-09-09
IOS json 解析遇到錯(cuò)誤問(wèn)題解決辦法
這篇文章主要介紹了iOS json 解析遇到error: Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed.解決辦法,需要的朋友可以參考下2017-01-01
iOS應(yīng)用開(kāi)發(fā)中圖片的拉伸問(wèn)題解決方案
這篇文章主要介紹了iOS應(yīng)用開(kāi)發(fā)中圖片的拉伸問(wèn)題解決方案,有時(shí)圖片的拉伸只需要拉伸中間部分而不拉伸兩端,這是本文所關(guān)注的問(wèn)題,需要的朋友可以參考下2016-02-02
基于iOS實(shí)現(xiàn)音樂(lè)震動(dòng)條效果
這篇文章主要為大家詳細(xì)介紹了基于iOS實(shí)現(xiàn)音樂(lè)震動(dòng)條效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-07-07
IOS開(kāi)發(fā)中如何設(shè)計(jì)短信驗(yàn)證碼防刷機(jī)制
給大家詳細(xì)分享一下在IOS的項(xiàng)目開(kāi)發(fā)中如何設(shè)計(jì)短信驗(yàn)證碼防刷機(jī)制,已經(jīng)步驟詳解,喜歡的朋友參考下吧。2018-02-02
微信JSSDK多圖片上傳并且解決IOS系統(tǒng)上傳一直加載的問(wèn)題
這篇文章主要介紹了微信JSSDK多圖片上傳并且解決IOS系統(tǒng)上傳一直加載的問(wèn)題的相關(guān)資料,需要的朋友可以參考下2016-03-03

