0

我在我的应用程序中有一个ViewController需要UIScrollView

在这UIScrollView我有很多UIButton。当我按下我触摸的按钮下方的一个按钮时,我想显示一个UIView动画他的入口。就像手风琴一样,像这样:Jquery demo

目前我有这种方法来打开“手风琴”:

-(void) openView:(UIView *)view inFrame:(CGRect)final {
  CGRect frame = view.frame;
  frame.size.height = 0;
  frame.origin = finalFrame.origin;
  view.frame = frame;

  [self.buttonsView addSubview:view];

  [UIView animateWithDuration:1.0 animations:^{
    view.frame = finalFrame;
  } completion:^(BOOL finished){
  }];
}

self.buttonsViewUIView我在我的scrollview.

使用这种方法,我可以在按钮后插入视图。但问题是:我无法打开按钮之间的空间来放大我的buttonsView

有没有办法做到这一点?

button1
button2
button3

点击按钮 2:

button1
button2
a view
button3

再次单击按钮 2:

button1
button2
button3

而且我不能使用UITableView

4

2 回答 2

0

请试试这个

//在.h文件中声明一个变量

IBOutlet UIButton *btnpreviouslySelected;
CGRect customerButtonFrame,inventoryButtonFrame,templatesButtonFrame;

考虑 btnCustomer、btnInventroy、btntemplate 是您的三个按钮并将它们分别分配为 1、2、3 标记。viewsearch 是您要在两个按钮之间添加的新视图

//在.m

//in view did load method set following 
btnpreviouslySelected=nil;
customerButtonFrame=btnCustomer.frame;
inventoryButtonFrame=btnInventory.frame;
templatesButtonFrame=btnTemplates.frame;


-(void) RepositioningFrameMneuTree
{
    btnCustomer.frame=customerButtonFrame;
    btnInventory.frame=inventoryButtonFrame;    
    btnTemplates.frame=templatesButtonFrame;    
}

-(void) RepositioningMenuTree:(int)iCaseValue
{
    if (iCaseValue==1) 
    {
        btnInventory.center=CGPointMake(btnInventory.center.x,btnInventory.center.y+300);

    }

    if (iCaseValue==2 || iCaseValue==1) 
    {
        btnTemplates.center=CGPointMake(btnTemplates.center.x,btnTemplates.center.y+300);

    }
}


-(IBAction) buttonClicked:(UIButton*)btn;
{       

        if(btnpreviouslySelected==btn)
        {

            //set to default location
            [UIView beginAnimations:nil context:NULL];
            [UIView setAnimationDuration:0.5];
            //here remove search view
            [viwSearchView removeFromSuperview];

            [self RepositioningFrameMneuTree];           
            [UIView commitAnimations];
            return;
        }

        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.5];      


        //assign previousbutton to new button
        btnpreviouslySelected=btn;
            [self RepositioningFrameMneuTree]; 



            viwSearchView.frame=CGRectMake(0,btn.frame.origin.y+45,viwSearchView.frame.size.width,viwSearchView.frame.size.height);


            //add search view on your view
            [self.buttonsview addSubview:viwSearchView];


        //-------------------------------------------
        //change the location of button below selected button to show the search button
        switch (btn.tag) {

            case 1:

                [self RepositioningMenuTree:1];
                break;
            case 2:

                [self RepositioningMenuTree:2];
                break;
            case 3:
                //dont do any thing
                break;

            default:
                break;
        }
        //end animation
        [UIView commitAnimations];




}
于 2012-11-19T05:19:59.293 回答
0

修改您的openView:inFrame:方法以同时为您点击的按钮下方的所有按钮的框架设置动画。

于 2012-11-19T04:10:51.347 回答