2010-12-06 7 views
3

일종의 확장 가능한 접을 수있는 UIView를 만들어야하고 제 3 자 컨트롤에 대해 비용을 지불 할 수 없습니다. 확장하거나 축소 사이에 사용자가 전환 할 수 있습니다 그 상단에접을 수있는 UIView를 만드는 방법

가있는 UIButton (또는 유사)이 있어야한다 :

내가 그것을 행동하고자하는 방법 기본적으로.

펼쳤을 때 다른 UIView (예 : 캘린더)를 배치하고 싶을 때 접힌 상태에서 주변 컨트롤이 위로 이동해야합니다.

사람이 간단하게 구현하는 방법에 어떤 아이디어가 있습니까 - 여기 멍청한 놈 :(

답변

7

서브 클래스의 ViewController를하고 버튼을 '붕괴'와, 이것은 당신이 시작할 수 있습니다 '확장'처럼 발사 수있는 두 가지 방법이있다 : 동적 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

당신은 (프로그래밍 방식 XIB 나) UIView의 추가 시도 할 수 오프 SCR을 그런 다음 UIView 애니메이션을 사용하여 기본보기 영역으로 슬라이드합니다.

버튼에는 애니메이션을 전환하는 IBAction이 있습니다 (슬라이드 인/슬라이드 아웃). 화면 밖으로 슬라이드 다음 UIView 숨겨진 된 속성을 true로 설정할 수 있습니다. IBAction을 호출 할 때보기의 숨김 속성이 true인지 확인해야합니다. 그렇다면 슬라이딩 애니메이션을 재생하는 것을 알고, 그렇지 않다면 슬라이딩 애니메이션을 재생합니다.

관련 문제