iOS UI-手势(Gesture)

时间:2023-03-09 15:58:29
iOS UI-手势(Gesture)
 #import "ViewController.h"

 @interface ViewController ()<UIActionSheetDelegate>
@property (strong, nonatomic) UITextField *me_textfield; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
[self.view setBackgroundColor:[UIColor lightGrayColor]];
/*
手势分类:
滑动手势、点击手势、双击手势、长按手势等7种
*/ // self.me_textfield = [[UITextField alloc] initWithFrame:CGRectMake(0, 100, 375, 100)];
// self.me_textfield.placeholder = @"请输入";
// self.me_textfield.borderStyle = UITextBorderStyleRoundedRect;
// //self.me_textfield.center =self.view.center;
// [self.view addSubview:self.me_textfield]; //创建点击手势
UITapGestureRecognizer *click = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickToDoSomething)];
[self.view addGestureRecognizer:click]; //创建长按手势
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressToDoSomething)];
longPress.minimumPressDuration = 2.0;
[self.view addGestureRecognizer:longPress]; //创建捏合手势
UIPinchGestureRecognizer *pich = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pichToDoSomething)];
[self.view addGestureRecognizer:pich]; //创建旋转手势
UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationToDoSomething)];
[self.view addGestureRecognizer:rotation]; //创建轻扫手势
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeToDoSomething)];
[self.view addGestureRecognizer:swipe]; //创建拖动手势
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panToDoSomething)];
[self.view addGestureRecognizer:pan]; //创建屏幕边缘拖动手势
UIScreenEdgePanGestureRecognizer *screenEdgePan =[[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(screenEdgePanToDoSomething)];
[self.view addGestureRecognizer:screenEdgePan];
}
#pragma mark - 屏幕边缘拖动手势关联方法
- (void)screenEdgePanToDoSomething
{
NSLog(@"屏幕边缘拖动");
}
#pragma mark - 拖动手势关联方法
- (void)panToDoSomething
{
NSLog(@"拖动");
}
#pragma mark - 轻扫手势关联方法
- (void)swipeToDoSomething
{
NSLog(@"轻扫");
}
#pragma mark - 旋转手势关联方法
- (void)rotationToDoSomething
{
NSLog(@"旋转");
}
#pragma mark - 捏合手势关联方法
- (void)pichToDoSomething
{
NSLog(@"捏合");
}
#pragma mark - 长按手势关联方法
- (void)longPressToDoSomething
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"关机" message:@"" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定",nil];
[alert show];
}
#pragma mark - 点击手势关联方法
- (void)clickToDoSomething
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"你点我试试" message:@"" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定",nil];
[alert show]; } - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end