2013-05-06 137 views
0

我创建包含在父视图的底部3个按钮隐藏的表单,通过按下另一个按钮,视图变得可见,但是那些3个按钮没有按下。我不太知道什么问题是。添加按钮

我通过代码添加一个按钮。这是按下按钮时调用的方法。

- (IBAction) addData:(id)sender 

{

if(attachInfo==nil){ 
     float screenHeight = self.view.frame.size.height; 
     attachInfo=[[UIView alloc] initWithFrame:CGRectMake(0, screenHeight, 320, 216)]; 



     UIButton *attachImage = [UIButton buttonWithType:UIButtonTypeCustom]; 
     //attachImage.enabled = YES; 
     [attachImage addTarget:self action:@selector(addImage:) forControlEvents:UIControlEventTouchUpInside]; 
     [attachImage setFrame:CGRectMake(20, 20, 0, 0)]; 
     [attachImage setImage:[UIImage imageNamed:@"add_photos"] forState:UIControlStateNormal]; 
     [attachImage sizeToFit]; 
     [attachInfo addSubview:attachImage]; 



     UIButton *attachDoc = [UIButton buttonWithType:UIButtonTypeCustom]; 
     //[pushButton addTarget:self action:@selector(pushViewController) forControlEvents:UIControlEventTouchUpInside]; 
     [attachDoc setFrame:CGRectMake(120, 20, 80, 80)]; 
     [attachDoc setImage:[UIImage imageNamed:@"add_docs.png"] forState:UIControlStateNormal]; 
     [attachDoc sizeToFit]; 
     [attachInfo addSubview:attachDoc]; 

     UIButton *attachPlace = [UIButton buttonWithType:UIButtonTypeCustom]; 
     //[pushButton addTarget:self action:@selector(pushViewController) forControlEvents:UIControlEventTouchUpInside]; 
     [attachPlace setFrame:CGRectMake(220, 20, 80, 80)]; 
     [attachPlace setImage:[UIImage imageNamed:@"add_place.png"] forState:UIControlStateNormal]; 
     [attachPlace sizeToFit]; 
     [attachInfo addSubview:attachPlace]; 

     //[self.view addSubview:attachInfo]; 
     [self.view addSubview:attachInfo]; 

     [UIView animateWithDuration:0.3f animations:^{ 
      CGRect frame = attachInfo.superview.frame; 
      frame.origin.y -= 216; 
      attachInfo.superview.frame=frame; 
     }]; 






    } 
    else 
    { 
     [UIView animateWithDuration:0.3f animations:^{ 
      CGRect frame = attachInfo.superview.frame; 
      frame.origin.y += 216; 
      attachInfo.superview.frame=frame; 
     }]; 
     attachInfo=nil; 
    } 



} 
+4

向我们展示一些代码上下工夫;) – Ushan87 2013-05-06 11:05:46

+0

请发表您的用于显示view.Whether您添加编码或XIB这些按钮的代码?清楚解释。 – NSUserDefault 2013-05-06 11:05:49

+0

邮政编码,你试过吗? – Rushabh 2013-05-06 11:05:49

回答

0

你需要添加按钮的作用。

- (IBAction)first:(id)sender; 
    { 

    firstViewController * fvc=[FirstViewController alloc]init]; 

    [FirstButton setHidden:False]; 


    [self.navigationController pushViewController:fvc animated:YES]; 




    } 
    - (IBAction)Second:(id)sender; 
    { 

    SecondViewController * svc=[SecondViewController alloc]init]; 


    [SecondButton setHidden:False]; 

    [self.navigationController pushViewController:svc animated:YES]; 

    } 
    - (IBAction)Third:(id)sender; 
    { 

    ThirdViewController * tvc=[ThirdViewController alloc]init]; 

    [ThirdButton setHidden:False]; 

    [self.navigationController pushViewController:fvc animated:YES]; 

    } 
+0

按钮是挂起的方法。 – Max 2013-05-06 11:15:36

+0

他不想解雇任何方法。他只是想启用按钮点击..? – Mani 2013-05-06 11:16:51

+0

检查您的xib您的插座和IBAction连接是否正确连接或没有。 – Jitendra 2013-05-06 11:17:28

0

在第一个按钮(attachImage)中,高度和宽度为零。所以它不应该是可见的。对于其他两个按钮,您尚未设置目标。所以那些是不可点击的。

为第一个按钮设置

[attachImage setFrame:CGRectMake(20, 20, 80, 80)]; 

和其他两个按钮添加

//for the second button 
[attachDoc addTarget:self action:@selector(addImage:) forControlEvents:UIControlEventTouchUpInside]; 

//for the third button 
[attachPlace addTarget:self action:@selector(addImage:) forControlEvents:UIControlEventTouchUpInside]; 
+0

这是行不通的(( – Max 2013-05-06 12:41:02

+0

你有没有改变框的大小和这些目标添加到您的另外两个按钮? – Ushan87 2013-05-06 12:45:23

+0

我尝试了所有的选项,没有什么工作 – Max 2013-05-06 13:02:12

0
-(void)createHiddenForm 
{ 
    hiddenView = [[UIView alloc] initWithFrame:CGRectMake(0,100,320,300)]; 
    [hidden setHidden:TRUE]; 

    [self.view addSubview:hiddenView]; 

    float posY = 50.0; 

    for (int i=0 ; i<3 ; i++) 
    { 
     UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
     [button setFrame:CGRectMake(50,posY, 100, 50)]; 
     [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; 

     [hiddenView addSubview:button]; 

     posY=posY+60; 
    } 
} 

-(void)showHiddenView 
{ 
     hidden.hidden = FALSE; 
     [self.view bringSubviewToFront:hiddenView]; 
} 

-(void)buttonClicked:(id)sender 
{ 
     UIButton *senderBtn = (UIButton *)sender; 

     NSLog(@"Sender Button's tag = %@",senderBtn.tag); 
} 

希望它会帮助你。

0
float screenHeight = self.view.frame.size.height; 
attachInfo=[[UIView alloc] initWithFrame:CGRectMake(0, screenHeight, 320, 216)]; 

从以上所述,您可以在视图边界之外添加attachInfo Y位置。 在视图外添加按钮onclick将不起作用。

使其工作取代下面的线。

[UIView animateWithDuration:0.3f animations:^{ 
     CGRect frame = attachInfo.superview.frame; 
     frame.origin.y -= 216; 
     attachInfo.superview.frame=frame; 

而不是移动超视图帧移动attachInfo框架就像这样。

[UIView animateWithDuration:0.3f animations:^{ 
     CGRect frame = attachInfo.frame; 
     frame.origin.y -= 216; 
     attachInfo.frame=frame; 

因此,attachInfo视图将被添加到超级视图边界与动画。

+0

如何使这项工作?我创建的屏幕外的视图,添加按钮和scrollView,并将其与动画块,超级视图一起移动,但没有任何元素不起作用(( – Max 2013-05-10 23:21:23