当用户在屏幕上点击时,弹出窗口应该会显示一个按钮。 但我不知道为什么按钮不显示在PopUp中。是否有问题,因为它是子视图中的子视图?将UIButton添加到子视图
-(void) popUpWithX:(int)x andY:(int)y {
CGRect popUpRect = CGRectMake(x, y, 125, 75);
popUp = [[UIView alloc] initWithFrame:popUpRect];
popUp.backgroundColor = [UIColor whiteColor];
popUp.layer.cornerRadius = 7.5f;
popUp.layer.masksToBounds = YES;
[self.view addSubview:popUp];
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
[button setTitle:@"Click me!" forState:UIControlStateNormal];
[popUp addSubview:button];
}
编辑:
是否有可能在UIButton的坐标是错误的?我不确定坐标系是来自主视图还是来自弹出子视图。
坐标来自弹出窗口,而不是主视图。这很可能不是问题。 –