UI_UIResponder

//

//  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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值