我正在尝试在代码中创建两个自定义按钮。一个用顶部的小按钮填满整个屏幕。我遇到的问题是点击较小的按钮时会触发较大的按钮。我尝试用IB做同样的事情并且它有效。我需要在代码中使用某种捕获/屏蔽方法吗?我已经检查了文档,但没有发现任何可能表明发生这种情况的事情。
CGRect bFrame = CGRectMake(0, 0, 320, 480);
UIButton *cancelButton = [[UIButton alloc] init];
cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
cancelButton.frame = bFrame;
[cancelButton setBackgroundColor:[UIColor clearColor]];
[cancelButton addTarget:self action:@selector(animate:) forControlEvents:UIControlEventTouchUpInside];
UIButton *priceButton = [[UIButton alloc] init];
priceButton.center = CGPointMake(228, 98);
[priceButton addTarget:self action:@selector(callNumber:) forControlEvents:UIControlEventTouchUpInside];
[priceButton setTitle:@"BUY" forState:UIControlStateNormal];
[self.view addSubview:priceButton];
//[cancelButton addSubview:priceButton];
[self.view addSubview:cancelButton];
[self.view bringSubviewToFront:priceButton];
答案 0 :(得分:0)
您是否忘记引用[self.view addSubview:priceButton];
或者您的代码中是否遗漏了这些内容?