2010-12-06 18 views
3

何らかの種類の拡張可能な折りたたみ可能なUIViewを作成する必要があり、サードパーティ製のコントロールを支払うことができません。折りたたみ可能なUIViewを作成するには

これは、私はそれが動作するように希望の方法を基本的には次のとおりです。

上部には、ユーザが拡大し、崩壊の間で切り替えることができますUIButton(または類似)があるはずです。

拡張時他のUIView(カレンダーなど)を配置したい場合、折り畳まれたときに周囲のコントロールが上に移動する必要があります。

誰もこれだけで実装する方法任意のアイデアを持っています - ここのnoob :(

答えて

7

サブクラスのViewControllerをし、あなたのボタンは「崩壊」と、これはあなたが始められるかもしれない「拡大」のよう発射できる2つの方法があります:あなたは、動的にUIButtonsに新しいセレクタを割り当てることができます。

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

コード:

#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 
    } 
} 
0

あなたはSCRオフのUIView(XIB中またはプログラム)を追加してみてください可能性を次に、UIViewアニメーションを使用してメインビュー領域にスライドさせます。

ボタンにはアニメーションを切り替える(スライドイン/スライドアウト)IBActionがあります。画面からスライドさせて、UIViewのhiddenプロパティをtrueに設定することができます。 IBActionを呼び出すときは、ビューのhiddenプロパティがtrueであるかどうかをチェックします。それがそうであれば、あなたはそれのアニメーションをプレイすることを知っています、そうでなければ、スライドアウトのアニメーションを再生します。

関連する問題