我正在开发一个应用程序,当我按下菜单按钮时,IBAction会创建一个覆盖图(添加一个子视图)。此子视图必须包含必须可访问的按钮。我最初通过在前一个视图中添加额外按钮而犯了一个错误。因此,当我按下菜单按钮时,新的覆盖图弹出,无法访问额外的按钮。有什么建议吗?我是iOS编程的新手。谢谢
- (IBAction) btnMoveTo:(id)sender
{
UIButton* button= (UIButton*)sender;
[self overlayCheck];
[movingButton setHidden:false];
[movingButton2 setHidden:false];
[movingButton3 setHidden:false];
[movingButton moveTo:
CGPointMake(125,250) duration:0.8
option:curveValues[selectedCurveIndex]];
[movingButton2 moveTo:
CGPointMake(25,250) duration:0.8
option:curveValues[selectedCurveIndex]];
[movingButton3 moveTo:
CGPointMake(225,250) duration:0.8
option:curveValues[selectedCurveIndex]];
}
-(void)overlayCheck{
CGRect frame = [homeButton frame];
UIView* view = [[UIView alloc] initWithFrame:CGRectMake(frame.origin.x - FrameSizeIncreaseAmount, frame.origin.y - FrameSizeIncreaseAmount, frame.size.width + FrameSizeIncreaseAmount * 2, frame.size.height + FrameSizeIncreaseAmount * 2)];
view.backgroundColor = [UIColor blackColor];
[self.view addSubview:view];
[UIView beginAnimations:@"fade in" context:nil];
[UIView setAnimationDuration:0.2];
[view setBackgroundColor:[[UIColor grayColor] colorWithAlphaComponent:MaxAlpha]];
[UIView commitAnimations];
}
movingButton,movingButton2和movingButton3应该在新视图上。叠加层不允许我访问按钮。
答案 0 :(得分:0)
不确定我是否理解正确,但您应将按钮添加到您在overlayCheck方法中创建的叠加层视图中:
-(void)overlayCheck
{
CGRect frame = [homeButton frame];
UIView* view = [[UIView alloc] initWithFrame:CGRectMake(frame.origin.x - FrameSizeIncreaseAmount, frame.origin.y - FrameSizeIncreaseAmount, frame.size.width + FrameSizeIncreaseAmount * 2, frame.size.height + FrameSizeIncreaseAmount * 2)];
view.backgroundColor = [UIColor blackColor];
// ---------------------------------------------
// Becareful how you set the frame X-Y coordinate
// for your button if your moving buttons uses
// initWithFame:CGRectMake(X,Y,Width,Height);
//
// The X,Y are relative to the parent view
// that you add the moving buttons to
// ---------------------------------------------
[view addSubview:movingButton1];
[view addSubview:movingButton2];
[view addSubview:movingButton3];
[self.view addSubview:view];
[UIView beginAnimations:@"fade in" context:nil];
[UIView setAnimationDuration:0.2];
[view setBackgroundColor:[[UIColor grayColor] colorWithAlphaComponent:MaxAlpha]];
[UIView commitAnimations];
}