2011-11-03 6 views
4

버튼을 누르거나 무엇이든간에 내 앱에서 무언가를 요청하면 "로딩 .."이라는 작은 사각형이 나타나기를 원합니다. 완료되면 "슬라이드 업 효과"와 함께 사라집니다. 나는 달성하려는 것을 잘 묘사하기위한 간단한 모형을 만들었습니다. 나 한테 어떤 힌트가 있니? 감사.iPhone 로딩보기 "슬라이드 효과"

enter image description here

참고 : 내가 원하지 않는 효과를 당겨서 새로 고침 (로드 뷰는 코멘트를 보낼 때, 예를 들어 표시, 화면 스크롤없이 나타납니다)

UPDATE :

- (IBAction)displayLoadingScreen:(id)sender 
{ 
    NSLog(@"pressed"); 
    UIView *loadingView = [[UIView alloc] init]; 
    loadingView.frame = CGRectMake(0,-40,320,40); 
    [loadingView setBackgroundColor:[UIColor blueColor]]; 
    [self.view addSubview:loadingView]; 
    //animate in within some method called when loading starts 
    [UIView animateWithDuration:1.0 
        animations:^{ 
         loadingView.frame = CGRectMake(0,0,320,40); 
        } 
        completion:^(BOOL finished) { 
        }]; 
    for (int i = 0; i < 10000; i++) { 
     NSLog(@"%d", i); 
    } 
    //animate out within some method called when loading ends 
    [UIView animateWithDuration:1.0 
        animations:^{ 
         loadingView.frame = CGRectMake(0,-40,320,40); 
        } 
        completion:^(BOOL finished){ 


        }]; 
} 
:

은 내가 권층운 코드를 시도했습니다

for 루프 이후에 로딩 뷰가 왜 에 들어 있습니까? 시도한 후에 for 루프를 인쇄하기 전에 두 애니메이션을 실행합니다. 아이디어?

UPDATE 2

- (void)stopLoading { 
    [UIView animateWithDuration:1.0 
        animations:^{ 
         loadingView.frame = CGRectMake(0,-40,320,40); 
        } 
        completion:^(BOOL finished){ 
        }]; 
} 

- (void)startLoading { 
    loadingView.frame = CGRectMake(0,-40,320,40); 
    [loadingView setBackgroundColor:[UIColor blueColor]]; 
    [self.view addSubview:loadingView]; 
    //animate in within some method called when loading starts 
    [UIView animateWithDuration:1.0 
        animations:^{ 
         loadingView.frame = CGRectMake(0,0,320,40); 
        } 
        completion:^(BOOL finished) { 
        }]; 
    sleep(5); 
    [self stopLoading]; 
} 

- (IBAction)displayLoadingScreen:(id)sender 
{ 
    NSLog(@"button pressed"); 
    [self startLoading]; 
} 
+0

'UIAnimation' 클래스를 읽고 (그리고 QuartzCore 프레임 워크 사용) 시도해보십시오. – Raptor

+0

페이스 북처럼 슬라이드 다운 기능을 사용하려면 'EGOTableViewPullRefresh'사용을 고려하십시오. – Raptor

답변

5
loadingView.frame = CGRectMake(0,-40,320,40); 
[loadingView setBackgroundColor:[UIColor blueColor]]; 
[self.view addSubview:loadingView]; 
//animate in within some method called when loading starts 
[UIView animateWithDuration:1.0 
       animations:^{ 
        loadingView.frame = CGRectMake(0,0,320,40); 
       } 
       completion:^(BOOL finished){ 


       }]; 
//animate out within some method called when loading ends 
[UIView animateWithDuration:1.0 
       animations:^{ 
        loadingView.frame = CGRectMake(0,-40,320,40); 
       } 
       completion:^(BOOL finished){ 


       }]; 
+0

체크 아웃 내 업데이트하시기 바랍니다. 감사. –

+1

제 답변에서는 애니메이션을 별도의 메서드에 넣으라고했습니다. 하나는로드가 시작될 때 호출되고 다른 하나는로드가 끝날 때 호출됩니다. 애니메이션은 실행이 1 초가 걸리기 때문에 애니메이션이 끝나기 전에 실행됩니다. 실행은 다른 코드가 계속 진행될 때 수행됩니다. 그래서, 같은 방법으로 두 애니메이션을 간략히 말하면 안됩니다. 실제로로드가 시작될 때 호출하고 실제로로드가 완료되면 다른 호출을 호출하면 모두 유용 할 것입니다. –

+0

양해 해 주셔서 감사합니다. 그러나 그것은 저에게 효과적이지 않았습니다. 내 새 업데이트를 참조하십시오. 왜 실행되는 첫 번째 문장은 'sleep'이고 애니메이션의 첫 번째 슬라이드가 아닌가? –

1

내가 할 것이다 당신이 원하는 로딩 설계와 다른 뷰의 앞에보기를 추가합니다. 로딩이 (알림을 사용하거나 뷰의 함수를 호출)이 완료 될 때

그런 다음, 애니메이션의 종류와 그것을 밀어 :

[UIView animateWithDuration:0.3 
           delay:0 
          options:UIViewAnimationOptionAllowUserInteraction 
         animations:^{ 
          //change the frame to make the view go out of the screen 
         } 
         completion:^(BOOL finished){ 
          //do whatever you want with the view (release it for instance) 
         }]; 
0

당신이 다른 회 전자의 도움으로 그것을 할 수 있습니다 당신은 단지 좌표를 가지고 애니메이션을 설정하고 어떤 오브젝트를 클릭 할 때 당신의 뷰를 팝업 할 것이고 그것을로드 한 후에 팝업 뷰를 위해 '-'좌표 (프레임)를 설정해야합니다. ....