buttonをクリックしてビューを表示し、放して消えることについて!

2380 ワード

// 
- (void)viewDidLoad {
   
    [super viewDidLoad];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    
    button.frame = CGRectMake(50, 150, 50, 50);
    
    button.backgroundColor = [UIColor redColor];
    
    [button addTarget:self action:@selector(buttonClick0:) forControlEvents:UIControlEventTouchDown];
    
    [button addTarget:self action:@selector(buttonClick1:) forControlEvents:UIControlEventTouchDownRepeat];
    
    [button addTarget:self action:@selector(buttonClick2:) forControlEvents:UIControlEventTouchDragInside];
    
    [button addTarget:self action:@selector(buttonClick3:) forControlEvents:UIControlEventTouchDragOutside];
    
    [button addTarget:self action:@selector(buttonClick4:) forControlEvents:UIControlEventTouchDragEnter];
    
    [button addTarget:self action:@selector(buttonClick5:) forControlEvents:UIControlEventTouchDragExit];
    
    [button addTarget:self action:@selector(buttonClick6:) forControlEvents:UIControlEventTouchUpInside];
    
    [button addTarget:self action:@selector(buttonClick7:) forControlEvents:UIControlEventTouchDragOutside];
    
    [button addTarget:self action:@selector(buttonClick8:) forControlEvents:UIControlEventTouchCancel];
    
    [self.view addSubview:button];
    
    showView = [[UIView alloc]initWithFrame:CGRectMake(100, 200, 50, 50)];
    showView.backgroundColor = [UIColor blueColor];
}

- (void)buttonClick0:(UIButton *)sender {
    
    NSLog(@"000000");
    [self.view addSubview:showView];
}
- (void)buttonClick1:(UIButton *)sender {
    
    NSLog(@"111111");
}
- (void)buttonClick2:(UIButton *)sender {
    
    NSLog(@"22222");
}
- (void)buttonClick3:(UIButton *)sender {
    
    NSLog(@"333333");
}
- (void)buttonClick4:(UIButton *)sender {
    
    NSLog(@"4444");
}
- (void)buttonClick5:(UIButton *)sender {
    
    NSLog(@"55555");
}
- (void)buttonClick6:(UIButton *)sender {
    
    [showView removeFromSuperview];
    NSLog(@"6666");
}
- (void)buttonClick7:(UIButton *)sender {
    
    NSLog(@"77777");
}
- (void)buttonClick8:(UIButton *)sender {
    
    NSLog(@"8888");
}
- (void)buttonClick9:(UIButton *)sender {
    
    NSLog(@"999999");
}

// 000000 66666 , 00000 UIControlEventTouchDown , 66666 UIControlEventTouchUpInside .