#import "AppDelegate.h"
#import "ViewController.h"
#import "SecondViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
//--------------------------------------------------------------------------
ViewController *viewController = [[ViewController alloc]init];
self.window.rootViewController = viewController;
//--------------------------------------------------------------------------
// SecondViewController *secondVC = [[SecondViewController alloc]init];
// self.window.rootViewController = secondVC;
//--------------------------------------------------------------------------
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
#import "ViewController.h"
#import "TapView.h"
@interface ViewController ()<UIGestureRecognizerDelegate>
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//--------------------------------------------------------------------------
// 点击空白处回收键盘,通过轻拍手势
UITextField *myTextField = [[UITextField alloc]initWithFrame:CGRectMake(150 ,200, 150, 30)];
myTextField.borderStyle = UITextBorderStyleRoundedRect;
myTextField.placeholder = @"测试轻拍手势";
[self.view addSubview:myTextField];
//为当前界面增加轻拍手势,是的点击时可以回收键盘
//初始化轻拍手势
//回调方法所带的参数为手势本身
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hiddenKeyBoard:)];
//将手势添加到视图,只要视图的用户交互打开,不是关闭的,就可以响应手势
[self.view addGestureRecognizer:tapGestureRecognizer];
//--------------------------------------------------------------------------
//给头像上添加轻拍手势
UIImageView *headImageView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 250, 100, 100)];
[headImageView setImage:[UIImage imageNamed:@"zhang.png"]];
headImageView.layer.borderWidth = 4;
headImageView.layer.cornerRadius = 50;
headImageView.layer.masksToBounds = YES;
[self.view addSubview:headImageView];
//为headImageView添加手势
//初始化轻拍手势
//将手势团添加到imaheView
UITapGestureRecognizer *tapGestureRecognizer1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapImage:)];
[self.view addGestureRecognizer:tapGestureRecognizer1];
[headImageView setUserInteractionEnabled:YES];
[self.view setUserInteractionEnabled:YES];
//触发回调方法所需要的勤工爱次数
tapGestureRecognizer1.numberOfTouchesRequired = 5;
//需要触摸对象的个数
tapGestureRecognizer1.numberOfTouchesRequired = 2;
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipe:)];
//扫动方向(枚举值)
swipe.direction =(UISwipeGestureRecognizerDirectionUp |UISwipeGestureRecognizerDirectionDown);
[self.view addGestureRecognizer:swipe];
//--------------------------------------------------------------------------
//轻扫手势
UIScreenEdgePanGestureRecognizer *pan =[[UIScreenEdgePanGestureRecognizer alloc]initWithTarget:self action:@selector(pan:)];
pan.edges = UIRectEdgeRight;
[self.view addGestureRecognizer:pan];