iOS UI-手势(Gesture)

 1 #import "ViewController.h"
 2
 3 @interface ViewController ()<UIActionSheetDelegate>
 4 @property (strong, nonatomic) UITextField *me_textfield;
 5
 6 @end
 7
 8 @implementation ViewController
 9
10 - (void)viewDidLoad {
11     [super viewDidLoad];
12     [self.view setBackgroundColor:[UIColor lightGrayColor]];
13     /*
14      手势分类:
15      滑动手势、点击手势、双击手势、长按手势等7种
16      */
17
18 //    self.me_textfield = [[UITextField alloc] initWithFrame:CGRectMake(0, 100, 375, 100)];
19 //    self.me_textfield.placeholder = @"请输入";
20 //    self.me_textfield.borderStyle = UITextBorderStyleRoundedRect;
21 //    //self.me_textfield.center =self.view.center;
22 //    [self.view addSubview:self.me_textfield];
23
24     //创建点击手势
25     UITapGestureRecognizer *click = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickToDoSomething)];
26     [self.view addGestureRecognizer:click];
27
28     //创建长按手势
29     UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressToDoSomething)];
30     longPress.minimumPressDuration = 2.0;
31     [self.view addGestureRecognizer:longPress];
32
33     //创建捏合手势
34     UIPinchGestureRecognizer *pich = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pichToDoSomething)];
35     [self.view addGestureRecognizer:pich];
36
37     //创建旋转手势
38     UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationToDoSomething)];
39     [self.view addGestureRecognizer:rotation];
40
41     //创建轻扫手势
42     UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeToDoSomething)];
43     [self.view addGestureRecognizer:swipe];
44
45     //创建拖动手势
46     UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panToDoSomething)];
47     [self.view addGestureRecognizer:pan];
48
49     //创建屏幕边缘拖动手势
50     UIScreenEdgePanGestureRecognizer *screenEdgePan =[[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(screenEdgePanToDoSomething)];
51     [self.view addGestureRecognizer:screenEdgePan];
52 }
53 #pragma mark - 屏幕边缘拖动手势关联方法
54 - (void)screenEdgePanToDoSomething
55 {
56     NSLog(@"屏幕边缘拖动");
57 }
58 #pragma mark - 拖动手势关联方法
59 - (void)panToDoSomething
60 {
61     NSLog(@"拖动");
62 }
63 #pragma mark - 轻扫手势关联方法
64 - (void)swipeToDoSomething
65 {
66     NSLog(@"轻扫");
67 }
68 #pragma mark - 旋转手势关联方法
69 - (void)rotationToDoSomething
70 {
71     NSLog(@"旋转");
72 }
73 #pragma mark - 捏合手势关联方法
74 - (void)pichToDoSomething
75 {
76     NSLog(@"捏合");
77 }
78 #pragma mark - 长按手势关联方法
79 - (void)longPressToDoSomething
80 {
81     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"关机" message:@"" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定",nil];
82     [alert show];
83 }
84 #pragma mark - 点击手势关联方法
85 - (void)clickToDoSomething
86 {
87     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"你点我试试" message:@"" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定",nil];
88     [alert show];
89
90
91 }
92
93
94 - (void)didReceiveMemoryWarning {
95     [super didReceiveMemoryWarning];
96     // Dispose of any resources that can be recreated.
97 }
98
99 @end
时间: 2024-08-09 19:47:18

iOS UI-手势(Gesture)的相关文章

iOS开发之手势gesture详解(二)

与其他用户界面控件交互 UIControl子类会覆盖parentView的gesture.例如当用户点击UIButton时,UIButton会接受触摸事件,它的parentView不会接收到.这仅适用于手势识别重叠的默认动作的控制,其中包括: 一根手指单击动作:UIButton, UISwitch, UIStepper, UISegmentedControl, and UIPageControl. 一根手指擦碰动作:UISlider 一根手指拖动动作:UISwitch 包含多点触摸的事件 在iO

iOS开发之手势gesture详解(一)

前言 在iOS中,你可以使用系统内置的手势识别(GestureRecognizer),也可以创建自己的手势.GestureRecognizer将低级别的转换为高级别的执行行为,是你绑定到view的对象,当发生手势,绑定到的view对象会响应,它确定这个动作是否对应一个特定的手势(swipe,pinch,pan,rotation).如果它能识别这个手势,那么就会向绑定它的view发送消息,如下图 UIKit框架提供了一些预定义的GestureRecognizer.包含下列手势 UITapGestu

【腾讯TMQ】解放程序猿(媛)的双手—iOS UI自动化测试

解放程序猿(媛)的双手-iOS UI自动化测试 前言 随着移动互联网时代的蓬勃发展,移动终端的自动化测试也在业界日益活跃,总体来看在Android平台上的自动化工具和实践比较多,但是说到iOS平台无论从自动化工具的数量还是质量上就陡降了.究其原因,无外乎是iOS系统的封闭性,加上相对Android用户的数量少,导致对这个平台系统的自动化进展缓慢,据笔者了解到的情况,很多iOS平台的测试人员还处于纯手工测试模式,自动化程度和Android平台无法相论,更别提和PC端相比了. 然而越是困难的事,越是

iOS中手势的delaysTouchesBegan属性用法(挖坑)

@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css); @import url(/css/cuteeditor.css);iOS中手势的delaysTouchesBegan属性用法(挖坑),布布扣,bubuko.com

ios各种手势,很有意思

一.概述 iPhone中处理触摸屏的操作,在3.2之前是主要使用的是由UIResponder而来的如下4种方式: - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event  - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event  - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent

IOS Ui控件 修改位置和尺寸,代码添加控件

所有的UI控件最终都继承自UIView,UI控件的公共属性都定义在UIView中, UIView的常见属性 UIView *superview; 获得自己的父控件对象 NSArray *subviews; 获得自己的所有子控件对象 NSInteger tag; 控件的ID(标识),父控件可以通过tag来找到对应的子控件 CGAffineTransform transform; 控件的形变属性(可以设置旋转角度.比例缩放.平移等属性) CGRect frame; 控件所在矩形框在父控件中的位置和尺

IOS开发——手势 &amp; 传感器 &amp; 物理引擎

这次思维导图比较杂,demo已经全部上传到github上,小编的github地址是:狂戳 先看下效果图: 手势画板: 物理引擎: 传感器: IOS开发--手势 & 传感器 & 物理引擎

ios UI数据库 sqlite小型数据库的增、删、改、查、排序

#import "table.h" @implementation table // 1.创建表 每一列之间用',',如果存在就不创建 create table if not exists t_class( class_id integer primary key autoincrement, class_name varchar, person_count integer default 0) // 1.1// 删除表 drop table if exists t_person //

iOS UI框架

iOS UI 框架          启动引导页面 +  主界面 文件下载 UIFrame

iOS UI Tab开发

iOS UI Tab开发(iOS 8) tab这种样式,类似于单选,可以叫radio-style,这是一个现在主流的layout-design,它让APP内容结构清晰,开发分工逻辑明确,经典的就是微信,时钟等 综述一下: 1.UITabBarController继承UIViewController,是一个ViewController container 2.UITabBarController拥有一个(readonly)的TabBar,TabBar拥有一到多个TabBarItem 3.每一个It