2012-12-17 1 views
0

한 화면으로 매우 간단한 앱을 만들고 싶습니다. 결과적으로 같은보기 컨트롤러 내에서 두 개의보기가 필요합니다.단일 iOS 화면 내에서 애니메이션을 사용하여 UIView를 전환하는 방법

View1 - appear for 5 seconds 
View2 - appear during gameplay 
View1 - appear for 5 seconds 
View2 - appear during gameplay 
And so on. 

이 작업을 수행하는 방법을 모르지만이 디자인 패턴이 유효하다고 확신합니다.

나는 문서를 검색하지만 명확한 답을 찾을 수 없습니다.

나는이 작업을 수행 애플 리케이션을 알고 있지만, 어떻게 모르겠어요.

viewcontroller.view = View1 또는 View2입니까? 그렇다면 어떻게 멋진 애니메이션으로 전환 할 수 있습니까?

나는 애니메이션을 알고 있지만 사건의이 종류이다.

답변

1

당신의 ViewController의 관점의 파단으로 두 개의 뷰를 추가 ... 도와주세요 :

[viewController.view addSubview:view1]; 
[viewController.view addSubview:view2]; 

그런 다음 애니메이션 블록을 사용

// the following code will replace view1 with view2 after a 5 second delay 

// this ensures view2 is behind view1 
[viewController.view bringSubviewToFront:view2]; 
[viewController.view bringSubviewToFront:view1]; 

// get view2 ready for the animation 
view2.alpha = 0; 
view2.hidden = NO; 

// delay for 5 seconds before executing animation 
[UIView animateWithDuration:duration delay:5 options:(UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction) animations:^{ 

    //fade out 
    view1.alpha = 0; 

    // fade in 
    view2.alpha = 1; 

} completion:^(BOOL finished) { 

    // hide it after animation completes 
    view1.hidden = YES; 

    // bring view2 to front (even though view1 is not visible, it is still above view2) 
    [viewController.view bringSubviewToFront:view2]; 
}]; 

이 뷰 2와 뷰 1을 대체 할 수 있습니다. 등등.

관련 문제