//直接上代码
- (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的方法.
关于点击 button 让一个视图出现,松开后消失!
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...