0
我想在代碼中創建兩個自定義按鈕。一個用頂部的小按鈕填滿整個屏幕。我遇到的問題是點擊較小的按鈕時會觸發更大的按鈕。我試過用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];
糟糕,它滑掉了我的粘貼。我在我原來的代碼中。我修改了上面的代碼。 – Jim 2010-04-06 23:56:55
有道理,只是想確認一下。我應該把上面的內容寫成評論,而不是回答,因爲我現在沒有進一步的線索了,爲什麼你會得到這些結果 - 我的不好。 – Till 2010-04-07 00:05:31
感謝您的輸入。很高興知道這不是一件明顯的事情(除了我的貼)。 – Jim 2010-04-07 00:31:20