//
// ViewController.m
// UIResponder
//
// Created by HarrySun on 16/7/10.
// Copyright © 2016年 Mobby. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@property (nonatomic,strong) UIView *oneView;
@property (nonatomic,strong) UIView *twoView;
@property (nonatomic,strong) UIView *threeView;
@end
#define kWidth self.view.bounds.size.width
#define kHeight self.view.bounds.size.height
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
_oneView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kWidth, kHeight / 3)];
_oneView.backgroundColor = [UIColor redColor];
_twoView = [[UIView alloc] initWithFrame:CGRectMake(0, kHeight / 3, kWidth, kHeight / 3)];
_twoView.backgroundColor = [UIColor blueColor];
_threeView = [[UIView alloc] initWithFrame:CGRectMake(0, kHeight / 3 * 2, kWidth , kHeight / 3)];
_threeView.backgroundColor = [UIColor greenColor];
[self.view addSubview:_oneView];
[self.view addSubview:_twoView];
[self.view addSubview:_threeView];
[_oneView becomeFirstResponder]; // 成为第一响应者
}
#pragma mark - 触摸事件
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
NSLog(@"开始触摸");
NSLog(@"判断对象是否是第一响应者:%d",[_oneView isFirstResponder]); // 判断对象是否是第一响应者
NSLog(@"判断对象是否可以成为第一响应者:%d",[_oneView canBecomeFirstResponder]); // 判断对象是否可以成为第一响应者
NSLog(@"下一个响应者:%@",[_oneView nextResponder]); // 下一个响应者是什么
NSLog(@"判断对象是否可以取消第一响应者:%d",[_oneView canResignFirstResponder]); // 判断对象是否可以取消第一响应者
NSLog(@"对象放弃第一响应者:%d",[_oneView resignFirstResponder]); // 放弃第一响应者
[self.undoManager registerUndoWithTarget:self selector:@selector(undoAction:) object:@1]; // 注册撤销
[self.undoManager undo]; // 执行撤销
}
- (void)undoAction:(NSNumber *)num{
NSLog(@"%@",num);
[self.undoManager registerUndoWithTarget:self selector:@selector(undoAction:) object:num]; // 这是为了还原。撤销之后要及时register刚撤销的状态。
// 执行还原(出栈):
[self.undoManager redo];
}
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
NSLog(@"开始移动");
}
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
NSLog(@"结束触摸");
}
// 电话呼入等中断手势的事件
- (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
NSLog(@"取消触摸");
}
-(void)touchesEstimatedPropertiesUpdated:(NSSet *)touches{
NSLog(@"9.1之后加入的3Dtouch用的");
}
#pragma mark - 深按功能(iOS9之后)
- (void)pressesBegan:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event{
NSLog(@"开始按压");
}
- (void)pressesChanged:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event{
NSLog(@"按压选择");
}
- (void)pressesEnded:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event{
NSLog(@"按压结束");
}
- (void)pressesCancelled:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event{
NSLog(@"按压取消");
}
#pragma mark - 加速事件(陀螺仪和加速传感器)
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event{
NSLog(@"开始加速");
}
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event{
NSLog(@"结束加速");
}
- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event{
NSLog(@"加速中断");
}
#pragma mark - 远程控制事件
- (void)remoteControlReceivedWithEvent:(UIEvent *)event{
NSLog(@"远程控制事件");
}
#pragma mark -
- (BOOL)canPerformAction:(SEL)action withSender:(nullable id)sender{
return YES;
}
- (id)targetForAction:(SEL)action withSender:(id)sender{
return self;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end