- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章iOS手势的实现方法由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
本文实例为大家分享了ios手势的具体实现代码,供大家参考,具体内容如下 。
效果 。
细节 。
1.uitouch 。
。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
#import "viewcontroller_0.h"
@interface viewcontroller_0 ()
@property (nonatomic, strong)uilabel *label;
@end
@implementation viewcontroller_0
- (
void
)viewdidload {
[super viewdidload];
self.label = [[uilabel alloc] initwithframe:cgrectmake(100, 100, 100, 100)];
self.label.backgroundcolor = [uicolor yellowcolor];
self.label.layer.borderwidth = 1;
[self.view addsubview:self.label];
uilabel *textlabel = [[uilabel alloc] initwithframe:cgrectmake(10, 80, 200, 45)];
textlabel.text = @
"拖动方块"
;
[textlabel sizetofit];
textlabel.font = [uifont systemfontofsize:12];
[self.view addsubview:textlabel];
}
- (
void
)touchesbegan:(nsset<uitouch *> *)touches withevent:(nullable uievent *)event {
//1.拿到手势
uitouch *touch = [touches anyobject];
//2.拿到touch 所在view的坐标
cgpoint point = [touch locationinview:self.view];
//3.让label拿到坐标
self.label.center = point;
nslog(@
"1.手指接触到了屏幕"
);
}
- (
void
)touchesmoved:(nsset<uitouch *> *)touches withevent:(nullable uievent *)event {
//1.拿到手势
uitouch *touch = [touches anyobject];
//2.拿到touch 所在view的坐标
cgpoint point = [touch locationinview:self.view];
//3.让label拿到坐标
self.label.center = point;
nslog(@
"2.手指在屏幕上移动"
);
}
- (
void
)touchesended:(nsset<uitouch *> *)touches withevent:(nullable uievent *)event {
nslog(@
"3.手指刚离开屏幕"
);
}
- (
void
)touchescancelled:(nsset<uitouch *> *)touches withevent:(nullable uievent *)event {
nslog(@
"4.手势失效了"
);
}
@end
|
2.uitapgesturerecognizer 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#import "viewcontroller_1.h"
@interface viewcontroller_1 ()
@property (nonatomic, strong) uilabel *label;
@end
@implementation viewcontroller_1
- (
void
)viewdidload {
[super viewdidload];
uilabel *textlabel = [[uilabel alloc] initwithframe:cgrectmake(10, 80, 200, 45)];
textlabel.text = @
"电脑上操作tap手势 alt +shift 需要连续点击次数2次"
;
[textlabel sizetofit];
textlabel.font = [uifont systemfontofsize:12];
[self.view addsubview:textlabel];
self.label = [[uilabel alloc] initwithframe:cgrectmake(100, 150, 100, 100)];
self.label.backgroundcolor = [uicolor orangecolor];
self.label.userinteractionenabled = yes;
self.label.text = @
"0"
;
self.label.textalignment = nstextalignmentcenter;
[self.view addsubview:self.label];
// 1.创建tap手势
uitapgesturerecognizer *tap = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(labeltap:)];
tap.numberoftapsrequired = 2;
//需要轻轻点击的次数
tap.numberoftouchesrequired = 2;
//需要的手指数量 :2根手指alt +shift 需要匹配点击次数2次(其实直接用默认的就好)
[self.label addgesturerecognizer:tap];
}
- (
void
)labeltap:(uitapgesturerecognizer *)tap {
int
num = [self.label.text intvalue];
num++;
self.label.text = [nsstring stringwithformat:@
"%d"
,num ];
}
@end
|
3.uilongpressgesturerecognizer 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
#import "viewcontroller_2.h"
@interface viewcontroller_2 () <uigesturerecognizerdelegate>
@property (nonatomic, strong) uilabel *label;
@end
@implementation viewcontroller_2
- (
void
)viewdidload {
[super viewdidload];
uilabel *textlabel = [[uilabel alloc] initwithframe:cgrectmake(10, 80, 200, 45)];
textlabel.text = @
"long长按手势"
;
[textlabel sizetofit];
textlabel.font = [uifont systemfontofsize:12];
[self.view addsubview:textlabel];
self.label = [[uilabel alloc] initwithframe:cgrectmake(40, 150, 200, 150)];
self.label.backgroundcolor = [uicolor graycolor];
self.label.userinteractionenabled = yes;
self.label.text = @
"0"
;
self.label.textalignment = nstextalignmentcenter;
[self.view addsubview:self.label];
uilongpressgesturerecognizer *longpress = [[uilongpressgesturerecognizer alloc] initwithtarget:self action:@selector(longpressaction:)];
longpress.numberoftapsrequired = 1;
longpress.numberoftouchesrequired = 1;
longpress.minimumpressduration = 1.0;
longpress.delegate = self;
[self.label addgesturerecognizer:longpress];
}
- (
void
)longpressaction:(uilongpressgesturerecognizer *)longpress {
if
(longpress.state == uigesturerecognizerstatebegan) {
nslog(@
"手势状态开始"
);
}
else
if
(longpress.state == uigesturerecognizerstateended) {
nslog(@
"手势状态结束"
);
}
else
if
(longpress.state == uigesturerecognizerstatechanged) {
nslog(@
"手势状态改变"
);
nsinteger num = [self.label.text integervalue];
num ++;
self.label.text = [nsstring stringwithformat:@
"%ld"
,(
long
)num];
}
}
@end
|
4.uiswipegesturerecognizer 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
#import "viewcontroller_3.h"
@interface viewcontroller_3 ()
@property (nonatomic, strong) uilabel *label;
@end
@implementation viewcontroller_3
- (
void
)viewdidload {
[super viewdidload];
uilabel *textlabel = [[uilabel alloc] initwithframe:cgrectmake(10, 80, 200, 45)];
textlabel.text = @
"swipe手势 向右滑动➕1,你也可以设置左划上划下划"
;
textlabel.numberoflines = 0;
textlabel.font = [uifont systemfontofsize:12];
[self.view addsubview:textlabel];
self.label = [[uilabel alloc] initwithframe:cgrectmake(100, 150, 100, 100)];
self.label.backgroundcolor = [uicolor graycolor];
self.label.userinteractionenabled = yes;
self.label.text = @
"0"
;
self.label.textalignment = nstextalignmentcenter;
[self.view addsubview:self.label];
uiswipegesturerecognizer *swipegesture = [[uiswipegesturerecognizer alloc] initwithtarget:self action:@selector(swipeaction:)];
swipegesture.direction = uiswipegesturerecognizerdirectionright;
//默认就是向右划
[self.label addgesturerecognizer:swipegesture];
}
-(
void
)swipeaction:(uiswipegesturerecognizer *)swipe {
if
(swipe.direction == uiswipegesturerecognizerdirectionleft) {
nslog(@
"现在响应左划手势"
);
}
else
if
(swipe.direction == uiswipegesturerecognizerdirectionright) {
nslog(@
"现在响应右划手势"
);
nsinteger num = [self.label.text integervalue];
num ++;
self.label.text = [nsstring stringwithformat:@
"%ld"
,(
long
)num];
}
else
if
(swipe.direction == uiswipegesturerecognizerdirectionup) {
nslog(@
"现在响应上划手势"
);
}
else
if
(swipe.direction == uiswipegesturerecognizerdirectiondown) {
nslog(@
"现在响应下划手势"
);
}
}
@end
|
5.uipangesturerecognizer 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
#import "viewcontroller_4.h"
@interface viewcontroller_4 ()
@property (nonatomic, strong) uilabel *label;
@end
@implementation viewcontroller_4
- (
void
)viewdidload {
[super viewdidload];
uilabel *textlabel = [[uilabel alloc] initwithframe:cgrectmake(10, 80, 200, 45)];
textlabel.text = @
"pan手势,拖动方块"
;
[textlabel sizetofit];
textlabel.font = [uifont systemfontofsize:12];
[self.view addsubview:textlabel];
self.label = [[uilabel alloc] initwithframe:cgrectmake(100, 100, 100, 100)];
self.label.backgroundcolor = [uicolor graycolor];
self.label.userinteractionenabled = yes;
self.label.text = @
"0"
;
self.label.textalignment = nstextalignmentcenter;
[self.view addsubview:self.label];
uipangesturerecognizer *pan = [[uipangesturerecognizer alloc] initwithtarget:self action:@selector(panaction:)];
[self.label addgesturerecognizer:pan];
}
- (
void
)panaction:(uipangesturerecognizer *)pan {
cgpoint offset = [pan locationinview:self.view];
self.label.center = offset;
}
@end
|
6.uirotationgesturerecognizer 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
#import "viewcontroller_5.h"
@interface viewcontroller_5 ()
@property (nonatomic, strong) uilabel *label;
@end
@implementation viewcontroller_5
- (
void
)viewdidload {
[super viewdidload];
uilabel *textlabel = [[uilabel alloc] initwithframe:cgrectmake(10, 80, 200, 45)];
textlabel.text = @
"模拟器测试旋转手势时,按住 option键,再用触摸板或鼠标操作"
;
textlabel.font = [uifont systemfontofsize:12];
textlabel.numberoflines = 0;
[self.view addsubview:textlabel];
self.label = [[uilabel alloc] initwithframe:cgrectmake(40, 200, 200, 50)];
self.label.backgroundcolor = [uicolor graycolor];
self.label.userinteractionenabled = yes;
self.label.text = @
"we are friends"
;
self.label.textalignment = nstextalignmentcenter;
[self.view addsubview:self.label];
//(模拟器测试捏合和旋转手势时,按住 option 键,再用触摸板或鼠标操作)
uirotationgesturerecognizer *rotation = [[uirotationgesturerecognizer alloc] initwithtarget:self action:@selector(rotationaction:)];
[self.view addgesturerecognizer:rotation];
}
- (
void
)rotationaction:(uirotationgesturerecognizer *)rotation {
self.label.transform = cgaffinetransformrotate(self.label.transform, rotation.rotation);
rotation.rotation = 0;
// 这个很重要!!!!!
// static float orginstate;
//
// self.label.transform = cgaffinetransformmakerotation(rotation.rotation + orginstate);
//
// if (rotation.state == uigesturerecognizerstateended) {
//
// orginstate = orginstate + rotation.state;
// self.label.transform = cgaffinetransformmakerotation(rotation.rotation);
// }
}
@end
|
7.uipinchgesturerecognizer 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
#import "viewcontroller_6.h"
@interface viewcontroller_6 ()
@property (nonatomic, strong) uilabel *label;
@end
@implementation viewcontroller_6
- (
void
)viewdidload {
[super viewdidload];
uilabel *textlabel = [[uilabel alloc] initwithframe:cgrectmake(10, 80, 200, 45)];
textlabel.text = @
"模拟器测试捏合手势时,按住 option键,再用触摸板或鼠标操作"
;
textlabel.font = [uifont systemfontofsize:12];
textlabel.numberoflines = 0;
[self.view addsubview:textlabel];
self.label = [[uilabel alloc] initwithframe:cgrectmake(100, 250, 80, 80)];
self.label.backgroundcolor = [uicolor graycolor];
self.label.userinteractionenabled = yes;
self.label.text = @
"0"
;
self.label.textalignment = nstextalignmentcenter;
[self.view addsubview:self.label];
// (模拟器测试捏合和旋转手势时,按住 option 键,再用触摸板或鼠标操作)
uipinchgesturerecognizer * pinch = [[uipinchgesturerecognizer alloc]initwithtarget:self action:@selector(pichgesture:)];
[self.view addgesturerecognizer:pinch];
}
- (
void
)pichgesture:(uipinchgesturerecognizer *)pinch {
static
float
originscale = 1;
//手势缩放返回的scale 是相对于上一次的
self.label.transform = cgaffinetransformmakescale(pinch.scale * originscale , pinch.scale*originscale);
if
(pinch.state == uigesturerecognizerstateended) {
originscale = originscale * pinch.scale;
}
}
@end
|
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我.
最后此篇关于iOS手势的实现方法的文章就讲到这里了,如果你想了解更多关于iOS手势的实现方法的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
IO 设备如何知道属于它的内存中的值在memory mapped IO 中发生了变化? ? 例如,假设内存地址 0 专用于保存 VGA 设备的背景颜色。当我们更改 memory[0] 中的值时,VGA
我目前正在开发一个使用Facebook sdk登录(通过FBLoginView)的iOS应用。 一切正常,除了那些拥有较旧版本的facebook的人。 当他们按下“使用Facebook登录”按钮时,他
假设我有: this - is an - example - with some - dashesNSRange将使用`rangeOfString:@“-”拾取“-”的第一个实例,但是如果我只想要最后
Card.io SDK提供以下详细信息: 卡号,有效期,月份,年份,CVV和邮政编码。 如何从此SDK获取国家名称。 - (void)userDidProvideCreditCardInfo:(Car
iOS 应用程序如何从网络服务下载图片并在安装过程中将它们安装到用户的 iOS 设备上?可能吗? 最佳答案 您无法控制应用在用户设备上的安装,因此无法在安装过程中下载其他数据。 只需在安装后首次启动应
我曾经开发过一款企业版 iOS 产品,我们公司曾将其出售给大型企业,供他们的员工使用。 该应用程序通过 AppStore 提供,企业用户获得了公司特定的配置文件(包含应用程序配置文件)以启用他们有权使
我正在尝试将 Card.io SDK 集成到我的 iOS 应用程序中。我想为 CardIO ui 做一个简单的本地化,如更改取消按钮标题或“在此保留信用卡”提示文本。 我在 github 上找到了这个
我正在使用 CardIOView 和 CardIOViewDelegate 类,没有可以设置为 YES 的 BOOL 来扫描 collectCardholderName。我可以看到它在 CardIOP
我有一个集成了通话工具包的 voip 应用程序。每次我从我的 voip 应用程序调用时,都会在 native 电话应用程序中创建一个新的最近通话记录。我在 voip 应用程序中也有自定义联系人(电话应
iOS 应用程序如何知道应用程序打开时屏幕上是否已经有键盘?应用程序运行后,它可以接收键盘显示/隐藏通知。但是,如果应用程序在分屏模式下作为辅助应用程序打开,而主应用程序已经显示键盘,则辅助应用程序不
我在模拟器中收到以下错误: ImageIO: CGImageReadSessionGetCachedImageBlockData *** CGImageReadSessionGetCachedIm
如 Apple 文档所示,可以通过 EAAccessory Framework 与经过认证的配件(由 Apple 认证)进行通信。但是我有点困惑,因为一些帖子告诉我它也可以通过 CoreBluetoo
尽管现在的调试器已经很不错了,但有时找出应用程序中正在发生的事情的最好方法仍然是古老的 NSLog。当您连接到计算机时,这样做很容易; Xcode 会帮助弹出日志查看器面板,然后就可以了。当您不在办公
在我的 iOS 应用程序中,我定义了一些兴趣点。其中一些有一个 Kontakt.io 信标的名称,它绑定(bind)到一个特定的 PoI(我的意思是通常贴在信标标签上的名称)。现在我想在附近发现信标,
我正在为警报提示创建一个 trigger.io 插件。尝试从警报提示返回数据。这是我的代码: // Prompt + (void)show_prompt:(ForgeTask*)task{
您好,我是 Apple iOS 的新手。我阅读并搜索了很多关于推送通知的文章,但我没有发现任何关于 APNS 从 io4 到 ios 6 的新更新的信息。任何人都可以向我提供 APNS 如何在 ios
UITabBar 的高度似乎在 iOS 7 和 8/9/10/11 之间发生了变化。我发布这个问题是为了让其他人轻松找到答案。 那么:在 iPhone 和 iPad 上的 iOS 8/9/10/11
我想我可以针对不同的 iOS 版本使用不同的 Storyboard。 由于 UI 的差异,我将创建下一个 Storyboard: Main_iPhone.storyboard Main_iPad.st
我正在写一些东西,我将使用设备的 iTunes 库中的一部分音轨来覆盖 2 个视频的组合,例如: AVMutableComposition* mixComposition = [[AVMutableC
我创建了一个简单的 iOS 程序,可以顺利编译并在 iPad 模拟器上运行良好。当我告诉 XCode 4 使用我连接的 iPad 设备时,无法编译相同的程序。问题似乎是当我尝试使用附加的 iPad 时
我是一名优秀的程序员,十分优秀!