Iphone 如何创建可折叠的UIView

Iphone 如何创建可折叠的UIView,iphone,objective-c,cocoa,Iphone,Objective C,Cocoa,我需要创建某种可扩展和可折叠的UIView,但我无法支付第三方控件的费用 这就是我希望它的基本表现: 顶部应该有一个UIButton(或类似按钮),允许用户在展开和折叠之间切换 展开时,我希望能够放置其他UIView(如日历),折叠时,周围的控件应向上移动 有人知道如何简单地实现这一点吗?这里是noob:(将ViewController子类化,并有两种按钮可以触发的方法,如“折叠”和“展开”,这可能会让您开始:您可以动态地为UIButtons分配新的选择器: [button addTarget:

我需要创建某种可扩展和可折叠的UIView,但我无法支付第三方控件的费用

这就是我希望它的基本表现:

顶部应该有一个UIButton(或类似按钮),允许用户在展开和折叠之间切换

展开时,我希望能够放置其他UIView(如日历),折叠时,周围的控件应向上移动


有人知道如何简单地实现这一点吗?这里是noob:(

将ViewController子类化,并有两种按钮可以触发的方法,如“折叠”和“展开”,这可能会让您开始:您可以动态地为UIButtons分配新的选择器:

[button addTarget:self action:@selector(eventMethod:)
     forControlEvents:UIControlEventTouchUpInside];
代码:


您可以尝试在屏幕外添加UIView(在xib中或以编程方式),然后使用UIView动画将其滑入主查看区域

该按钮将有一个iAction,用于切换动画(滑入/滑出)。您可以将其滑出屏幕,然后将UIView的hidden属性设置为true。当您调用iAction时,让它检查视图的hidden属性是否为true。如果为true,则您知道如何播放其滑入动画,如果为true,则播放滑出动画

#define COLAPSED_HEIGHT 30

-(void)expand
    {   
        CGRect s= [self getScrerenBoundsForCurrentOriantation];
        CGRect f = self.view.frame;
        f.origin.y =s.size.height-self.view.frame.size.height;  
        [UIView beginAnimations:@"expand" context:NULL];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDidStopSelector:@selector(animationFinished:finished:context:)];    
        self.view.frame=f;

           //CHANGE YOUR EXPAND/COLLAPSE BUTTON HERE

        [UIView commitAnimations];
        self.thumbScrollerIsExpanded=YES;
    }

    -(void)collapseView
    {
        //re-factored so that this method can be called in ViewdidLoad
        CGRect s= [self getScrerenBoundsForCurrentOriantation];
        CGRect f = self.view.frame;

        f.origin.y =(s.size.height-COLAPSED_HEIGHT);

        self.view.frame = f;

        self.thumbScrollerIsExpanded=NO;    //thumbScrollerIsExpanded is a BOOL property
    }


    - (void)collapse
    {       
        [UIView beginAnimations:@"collapse" context:NULL];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDidStopSelector:@selector(animationFinished:finished:context:)];    
        [self collapseView];
           //CHANGE YOUR EXPAND/COLLAPSE BUTTON HERE    
        [UIView commitAnimations];

    }


-(CGRect)getScrerenBoundsForCurrentOriantation
{
    return [self getScrerenBoundsForOriantation:[[UIDevice currentDevice] orientation]];
}


-(CGRect)getScrerenBoundsForOriantation:(UIInterfaceOrientation)_orientation
{
    UIScreen *screen = [UIScreen mainScreen];
    CGRect fullScreenRect = screen.bounds; // always implicitly in Portrait orientation.        

    if (UIInterfaceOrientationIsLandscape(_orientation)) 
    {
        CGRect temp;
        temp.size.width = fullScreenRect.size.height;
        temp.size.height = fullScreenRect.size.width;
        fullScreenRect = temp;      
    }

    return fullScreenRect;
}

- (void)animationFinished:(NSString *)animationID finished:(BOOL)finished context:(void *)context
{   

    if ([animationID isEqualToString:@"expand"])
    {   
    //example
    }
else if ([animationID isEqualToString:@"collapse"])
    {   
    //example
    }
}