2010-12-06 50 views
3

我需要創建一個可擴展和可摺疊的某種UIView,並且無法支付第三方控件。如何創建一個可摺疊的UIView

這基本上是我怎麼想它的行爲:

在頂部應該有一個UIButton(或類似),允許用戶切換之間展開和摺疊。

展開後,我希望能夠放置其他UIView(例如日曆),並且在摺疊時周圍的控件應該向上移動。

沒有人有任何想法如何實現這個簡單 - 小白這裏:(

回答

7

子類視圖控制器,並有兩種方法,你的按鈕就可以火象「崩潰」和「擴大」,這可能讓你開始:您可以動態地分配新的選擇,以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

你可以嘗試添加一個UIView(無論是在廈門國際銀行或程序)關閉屏幕een,然後使用UIView動畫將其滑入您的主查看區域。

該按鈕將有一個IBAction,它將切換動畫(滑入/滑出)。你可以將它滑出屏幕,然後將UIView的隱藏屬性設置爲true。當您回想起IBAction時,請檢查視圖的隱藏屬性是否爲真。如果是的話,你知道要播放它的動畫,如果沒有,那麼你就播放滑出的動畫。

相關問題