添加一个新的视图的视图控制器 - iOS设备
问题描述:
我工作的一个应用程序,在那里当我按下菜单键,IBAction为创建一个具有覆盖(添加子视图)。这个子视图必须保存必须可访问的按钮。我最初通过添加额外的按钮到以前的观点犯了一个错误。因此,当我按下菜单按钮的新的覆盖弹出与没有被访问的额外的按钮。有什么建议吗?我是iOS编程的新手。谢谢添加一个新的视图的视图控制器 - 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];
}
moveButton,movingButton2和movingButton3应该在新视图上。覆盖层不允许我访问按钮。
答
不知道如果我理解正确,但你应该添加按钮,您的覆盖查看您在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];
}
你能告诉我们一些代码吗? – Aymarick 2012-07-10 09:51:04
这可能是因为你还没有联系的按钮到'IBAction'方法被后推调用。 – geminiCoder 2012-07-10 10:09:11