触摸  , 响应者链 , 摇一摇

36 篇文章 0 订阅
#import "RootViewController.h"
#import "RootV.h"
@interface RootViewController ()

@property (nonatomic, retain)RootV *rootV;
@property (nonatomic, retain)RootV *roooo;

@end

@implementation RootViewController

//   知识点  1:
//    响应者类
//    UIResponder

//     响应者链  从底层往上层传递 , 上层优先响应
//        当用户触摸屏幕,产生传递给应用,应用传递给 window ,window检测它上面所有的子视图,如果有子视图,事件传递给子视图,直到当前没有子视图,才开始判断自己能不能响应事件.自己响应不了就将事件抛给父视图响应.以此类推
//    事件检测从底层视图开始往子视图检测
//    事件响应是从子视图往下响应
//    当到达window 时都无法响应, 事件将会被抛弃

//    有两个控件的用户交互 默认是关闭的  UILabel  UIImageView
//    self.view.userInteractionEnabled = YES;   // 通过这个手势打开

//    当子视图的所在位置超出了父视图的范围时,点击超出的部分无法响应

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.view.backgroundColor = [UIColor grayColor];

    RootV *rootV = [[RootV alloc]initWithFrame:CGRectMake(40, 100, 100, 100)];
    rootV.backgroundColor = [UIColor redColor];
    [self.view addSubview:rootV];
    [rootV release];

// 知识点  2:
//    target - Action
//     3 .执行
    [rootV addMyTarget:self action:@selector(changecolor:)];


    RootV *roooo = [[RootV alloc]initWithFrame:CGRectMake(40, 250, 100, 100)];
    roooo.backgroundColor = [UIColor greenColor];
    [self.view addSubview:roooo];
    [roooo addMyTarget:self action:@selector(changePoin:)];
    [roooo release];



}

//     4. 步: 动作方法
- (void)changecolor:(RootV *)rootV {
    rootV.backgroundColor = [UIColor colorWithRed:arc4random() % 256 / 255.0 green:arc4random() % 256 / 255.0 blue:arc4random() % 256 / 255.0 alpha:1.0];

}

- (void)changePoin:(RootV *)ro {
    ro.center = CGPointMake(arc4random() % 300, arc4random() % 600);
}

// 手指触碰时触发
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
//    打印当前方法名
//    NSLog(@"%s", __FUNCTION__);
    NSLog(@"手指触碰时触发");
//    self.view.backgroundColor = [UIColor colorWithRed:arc4random() % 256 / 255.0 green:arc4random() % 256 / 255.0 blue:arc4random() % 256 / 255.0 alpha:1.0];
}

// 手指 移动时触发
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
//       NSLog(@"%s", __FUNCTION__);
//     self.view.backgroundColor = [UIColor colorWithRed:arc4random() % 256 / 255.0 green:arc4random() % 256 / 255.0 blue:arc4random() % 256 / 255.0 alpha:1.0];
}

//  手指离开时触发
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
//       NSLog(@"%s", __FUNCTION__);
//     self.view.backgroundColor = [UIColor colorWithRed:arc4random() % 256 / 255.0 green:arc4random() % 256 / 255.0 blue:arc4random() % 256 / 255.0 alpha:1.0];
}

// 触摸取消  (当来电话时,被动断开触发)
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
//       NSLog(@"%s", __FUNCTION__);
//     self.view.backgroundColor = [UIColor colorWithRed:arc4random() % 256 / 255.0 green:arc4random() % 256 / 255.0 blue:arc4random() % 256 / 255.0 alpha:1.0];
}

// 摇一摇 开始  摇一摇快捷键  conm + crtl + z
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
         self.view.backgroundColor = [UIColor colorWithRed:arc4random() % 256 / 255.0 green:arc4random() % 256 / 255.0 blue:arc4random() % 256 / 255.0 alpha:1.0];
}

// 摇一摇 结束
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {

}

// 摇一摇 中断
- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event {

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值