溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

IPhone開發(fā)文檔經(jīng)典語句

發(fā)布時間:2020-07-27 02:18:31 來源:網(wǎng)絡(luò) 閱讀:354 作者:NetworkAD 欄目:開發(fā)技術(shù)

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];
}

測試發(fā)現(xiàn)在view2上發(fā)生點擊事件,由于view2并不響應(yīng)該事件,于是將事件傳遞給它的父視圖,顏色發(fā)生改變,但是該點擊事件并不會通過view2傳遞給button,所以事件傳遞,僅傳遞給它的父視圖,也就是[superview addsubview:subview]中得superview



向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI