温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

IPhone开发文档经典语句

发布时间:2020-07-27 02:18:31 来源:网络 阅读:354 作者:NetworkAD 栏目:开发技术

1:When a touch occurs inside a specific view, the system sends an event object with the touch information directly to that view for handling. However, if the view does not handle a particular touch event, it can pass the event object along to its superview. If the superview does not handle the event, it passes the event object to its superview, and so on up the responder chain


测试:

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
    view.backgroundColor = [UIColor blueColor];
    
    UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(viewClick:)];
    
    [view addGestureRecognizer:tapGesture];
    
    UIView * view2 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
    view2.center = CGPointMake(self.view.frame.size.width/2.0, self.view.frame.size.height/2.0);
    view2.backgroundColor = [UIColor blackColor];
    [self.view addSubview:view];
    
    
    UIButton * button = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 60, 50)];
    button.backgroundColor = [UIColor redColor];
    [button addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];
    button.center = CGPointMake(self.view.frame.size.width/2.0, self.view.frame.size.height/2.0);
    [view addSubview:button];
    [view addSubview:view2];
}

- (void)buttonClick
{
    NSLog(@"buttonClick");
}

- (void)viewClick:(UITapGestureRecognizer *)tap
{
    int red =arc4random()%255;
    int green = arc4random()%255;
    int blue = arc4random()%255;
    NSLog(@"%d %d %d",red,green,blue);
    tap.view.backgroundColor = [UIColor colorWithRed:red/255.0 green:green/255.0 blue:blue/255.0 alpha:1];
}

测试发现在view2上发生点击事件,由于view2并不响应该事件,于是将事件传递给它的父视图,颜色发生改变,但是该点击事件并不会通过view2传递给button,所以事件传递,仅传递给它的父视图,也就是[superview addsubview:subview]中得superview



向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI