2014-02-01 8 views
0
UIView *background = [[UIView alloc] initWithFrame:self.view.bounds]; 
background.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height-70); 
[self.view addSubview:background]; 

UIView *background2 = [[UIView alloc] initWithFrame:CGRectMake(10, self.view.bounds.size.height-60, 300, 50)]; 
background2.backgroundColor = [UIColor whiteColor]; 
background2.layer.cornerRadius = 8; 
background2.layer.masksToBounds = YES; 
[background addSubview:background2]; 


UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; 
button.frame = CGRectMake(0, 0, 158, 50); 
[button setTitle:@"myButton" forState:UIControlStateNormal]; 
[button addTarget:self action:@selector(myButton:) forControlEvents:UIControlEventTouchUpInside]; 
[background2 addSubview:button]; 

кнопка не реагирует на касание? Зачем?UIView на UIView и UIButton не работает

+0

Почему вы звоните ' initWithFrame', а затем немедленное изменение кадра а потом? – Mundi

ответ

2
background.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height-70); 


UIView *background2 = [[UIView alloc] initWithFrame:CGRectMake(10, self.view.bounds.size.height-60, 300, 50)]; 

self.view.bounds.size.height-70 сравнивают это self.view.bounds.size.height-60 background2 из кадра фона кадра

enter image description here

установить фоновый кадр self.view.bounds.size.height теперь он прекрасно работает

enter image description here

+0

Определенно! После 12 часов кодирования я не понимал, что я делаю!)) –

0

Ваш код работает нормально, я просто попробовал. Я только сменил рамку background2, чтобы не быть за пределами рамки background.

Смежные вопросы