0

我正在开发一个应用程序,当我按下菜单按钮时,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。叠加层不允许我访问按钮。

4

1 回答 1

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];
}
于 2012-07-10T12:01:48.120 回答