向视图控制器添加新视图-iOS

向视图控制器添加新视图-iOS,ios,xcode,subview,Ios,Xcode,Subview,我正在开发一个应用程序,当我按下菜单按钮时,IBAction会创建一个覆盖(添加子视图)。此子视图必须包含可访问的按钮。我最初犯了一个错误,在上一个视图中添加了额外的按钮。因此,当我按下菜单按钮时,新的覆盖层弹出,额外的按钮无法访问。有什么建议吗?我是iOS编程的新手。多谢各位 - (IBAction) btnMoveTo:(id)sender { UIButton* button= (UIButton*)sender; [self overlayCheck]; [movingButt

我正在开发一个应用程序,当我按下菜单按钮时,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];


}

移动按钮、移动按钮2和移动按钮3应在新视图上显示。覆盖层不允许我访问按钮。

不确定我是否正确理解您的意思,但您应该将按钮添加到使用覆盖层检查方法创建的覆盖层视图中:

-(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];
}

您能给我们看一些代码吗?这可能是因为您没有将按钮链接到按下时调用的
iAction
方法。