UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
[self.view addGestureRecognizer:tap];
//輕拍次數(shù)
tap.numberOfTapsRequired = 1;
//需要幾個(gè)手指
tap.numberOfTouchesRequired = 1;
- (void)tapAction:(UITapGestureRecognizer *)tap
{
//得到 tag 值
NSInteger number = tap.view.tag;
NSString *number1 = [NSString stringWithFormat:@"%ld", number];
}
//向右滑動(dòng) 取消模態(tài)
UISwipeGestureRecognizer *swipeGestureRecognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeFrom:)];
[swipeGestureRecognizer setDirection:UISwipeGestureRecognizerDirectionRight];
[self.view addGestureRecognizer:swipeGestureRecognizer];
//右滑手勢(shì)
-(void)handleSwipeFrom:(UISwipeGestureRecognizer *)aaa
{
//如果是右滑
if (aaa.direction == UISwipeGestureRecognizerDirectionRight) {
[self.navigationController popViewControllerAnimated:YES];
}
}
// 創(chuàng)建長(zhǎng)按手勢(shì)
UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressGesture:)];
// 觸發(fā)長(zhǎng)按的時(shí)間
longPressGesture.minimumPressDuration = 0.5;
[cell addGestureRecognizer:longPressGesture];
-(void)longPressGesture:(UILongPressGestureRecognizer *)longPressGesture
{
if (longPressGesture.state == UIGestureRecognizerStateBegan) {
NSLog(@"長(zhǎng)按手勢(shì)開(kāi)啟");
longPressGesture.view .backgroundColor = [UIColor redColor];
}
if (longPressGesture.state == UIGestureRecognizerStateEnded) {
NSLog(@"長(zhǎng)按手勢(shì)結(jié)束");
longPressGesture.view .backgroundColor = [UIColor yellowColor];
}else {
NSLog(@"================");
}
}
// 創(chuàng)建拖拽手勢(shì)
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureAction:)];
[self.button addGestureRecognizer:panGesture];
//拖拽手勢(shì)
-(void)panGestureAction:(UIPanGestureRecognizer *)panGesture
{
//frame寫(xiě)法
CGPoint newCenter = CGPointMake([panGesture translationInView:panGesture.view].x + self.button.center.x, [panGesture translationInView:panGesture.view].y + self.button.center.y);
self.button.center = newCenter;
[panGesture setTranslation:CGPointZero inView:panGesture.view];
//masonry的初始化
[self.button mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.mas_equalTo(CGPointMake(0, 0)).priorityLow();
make.size.mas_equalTo(CGSizeMake(100, 100));
make.left.greaterThanOrEqualTo(self.view);
make.top.greaterThanOrEqualTo(self.view).offset(0);
make.bottom.right.lessThanOrEqualTo(self.view);
}];
//masonry寫(xiě)法
UIView *button = panGesture.view;
CGPoint newCenter = CGPointMake([panGesture translationInView:panGesture.view].x + button.center.x - [UIScreen mainScreen].bounds.size.width / 2, [panGesture translationInView:panGesture.view].y + button.center.y - [UIScreen mainScreen].bounds.size.height / 2);
[button mas_updateConstraints:^(MASConstraintMaker *make) {
make.center.mas_equalTo(newCenter).priorityLow();
}];
[panGesture setTranslation:CGPointZero inView:panGesture.view];
}
locationInView:獲取到的是手指點(diǎn)擊屏幕實(shí)時(shí)的坐標(biāo)點(diǎn)掩驱;
translationInView:獲取到的是手指移動(dòng)后棒仍,在相對(duì)坐標(biāo)中的偏移量
輕拍手勢(shì),左滑手勢(shì) 右滑手勢(shì) 長(zhǎng)按手勢(shì) 拖拽手勢(shì)
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
- 文/潘曉璐 我一進(jìn)店門(mén)侵俗,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)锨用,“玉大人,你說(shuō)我怎么就攤上這事隘谣≡鲇担” “怎么了?”我有些...
- 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)跪者。 經(jīng)常有香客問(wèn)我棵帽,道長(zhǎng),這世上最難降的妖魔是什么渣玲? 我笑而不...
- 正文 為了忘掉前任逗概,我火速辦了婚禮,結(jié)果婚禮上忘衍,老公的妹妹穿的比我還像新娘逾苫。我一直安慰自己,他們只是感情好枚钓,可當(dāng)我...
- 文/花漫 我一把揭開(kāi)白布铅搓。 她就那樣靜靜地躺著,像睡著了一般搀捷。 火紅的嫁衣襯著肌膚如雪星掰。 梳的紋絲不亂的頭發(fā)上,一...
- 那天嫩舟,我揣著相機(jī)與錄音氢烘,去河邊找鬼。 笑死家厌,一個(gè)胖子當(dāng)著我的面吹牛播玖,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播饭于,決...
- 文/蒼蘭香墨 我猛地睜開(kāi)眼蜀踏,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了掰吕?” 一聲冷哼從身側(cè)響起果覆,我...
- 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎畴栖,沒(méi)想到半個(gè)月后随静,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
- 正文 獨(dú)居荒郊野嶺守林人離奇死亡吗讶,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
- 正文 我和宋清朗相戀三年燎猛,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片照皆。...
- 正文 年R本政府宣布,位于F島的核電站候醒,受9級(jí)特大地震影響能颁,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜倒淫,卻給世界環(huán)境...
- 文/蒙蒙 一伙菊、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧敌土,春花似錦镜硕、人聲如沸。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至矩欠,卻和暖如春财剖,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背癌淮。 一陣腳步聲響...
- 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像策彤,于是被迫代替她去往敵國(guó)和親栓袖。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
推薦閱讀更多精彩內(nèi)容
- //聯(lián)系人:石虎QQ: 1224614774昵稱(chēng):嗡嘛呢叭咪哄 #import"ViewController.h"...
- 1、手勢(shì)識(shí)別器——UIGestureRecognizer 介紹在ios開(kāi)發(fā)中瑟俭,除了有關(guān)觸摸的這組方法來(lái)控制使用用者...
- #import "ViewController.h" @interface ViewController (){ ...
- self.navigationController.interactivePopGestureRecognizer...
- 上運(yùn)行時(shí)圖 使用方式,百公里加速只需要三行代碼: ItemTouchHelperCallback callback...