2012-06-28 6 views
1

저는 비교적 Objective-C 및 iOS 개발에 일반적으로 익숙하며 내 문제에 대한 도움과 안내를 부탁드립니다.[email protected]에서 MainView로 변경

나는 메인 및 플립형보기가있는 '유틸리티'앱인 첫 번째 앱을 작성했습니다. 이 응용 프로그램은 시뮬레이터와 내 iPhone에서 모두 예상대로 작동합니다. 그러나 Default.png 이미지에서 내 주보기로 눈에 띄고 갑작스런 변경이 있습니다.

나는 https://stackoverflow.com/a/9918650/1324822에서 n13의 제안 된 코드를 따라 왔지만, 내가 얻은 것 모두는 메인 뷰이며, 검은 색으로 변합니다.

내 코드는 다음에 AppDelegate.m 파일입니다 내에서 같이

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 

// set up your root view and stuff.... 
//.....(do whatever else you need to do)... 

// show the main window, overlay with splash screen + alpha dissolve... 
UIImageView *splashScreen = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Default.png"]]; 
[self.window addSubview:splashScreen];   
[self.window makeKeyAndVisible]; 

[UIView animateWithDuration:0.3 animations:^{splashScreen.alpha = 0.0;} 
       completion:(void (^)(BOOL)) ^{ 
        [splashScreen removeFromSuperview]; 
       } 
]; 
return YES; 
} 

나는 원인을 이해하는 것이 매우 날카로운입니다하지만 내가, 내가 내 프로젝트의이 부분을 '해결 해보려고 하는것'하고 인정합니다 문제 및 해결 방법에 대해 설명합니다. 내 mainView 어딘가에 명시해야 할 수도 있습니다, 아마도 주석으로 초기화 할 수 있지만이 작업을 수행하는 방법을 확실하지 오전 유일한 조건은 return YES; 설정하는 것입니다.

도움이 될 경우 스토리 보드 프로젝트입니다. Xcode 4.3.3을 실행 중입니다.

다시 한번 감사드립니다.

내가 대신 볼 첫 번째 화면에서 앱 위임에 넣어하지 않습니다

+0

스토리 보드를 사용하는 경우 끌어서 놓기를 사용하지 않는 이유는 무엇입니까? 나는 당신이 객관성에 새로운 사람이라면 가능한 한 적은 코드로 글을 써 보라고 권합니다. – Dustin

+0

이렇게하면 위의 페이드 인 전환을 만들 수 있습니까? 나는 코드를 작성하고 싶지만 더 중요한 것은 그것을 이해한다. –

+0

예, 전환 유형을 설정할 수 있습니다 – Dustin

답변

2

이 나는 ​​화면을 스플래시 않는 방법이다. rootViewController에 두 개의 인스턴스 변수가 필요합니다. 첫 번째는 UIView * 검정이고 두 번째는 UIImageView * splash입니다. 그런 다음 : 다음

-(void) viewWillAppear:(BOOL)animated { 

static dispatch_once_t onceToken; 
dispatch_once(&onceToken, ^{ 

    self.view.userInteractionEnabled = NO; 
    black = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds]; 
    black.backgroundColor = [UIColor blackColor]; 


    splash = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds]; 

    UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; 
    [splash addSubview:indicator]; 
    indicator.center = CGPointMake([UIScreen mainScreen].bounds.size.width/2, 455); 

    [indicator startAnimating]; 
    //the indicator part is arbitrary, of course 

    splash.image = [UIImage imageNamed:@"Default.png"]; 

    [self.view addSubview:black]; 
    [self.view addSubview:splash]; 

}); 


} 

:

-(void) viewDidAppear:(BOOL)animated { 

static dispatch_once_t onceToken; 
dispatch_once(&onceToken, ^{ 



    [UIView animateWithDuration:0.4 delay:2 options:UIViewAnimationCurveEaseInOut animations:^{ 
     splash.alpha=0; 
    } completion:^(BOOL finished) { 
     [splash removeFromSuperview]; 

     [UIView animateWithDuration:0.45 delay:0.2 options:UIViewAnimationCurveEaseInOut animations:^{ 
      black.alpha = 0; 
     } completion:^(BOOL finished) { 
      [black removeFromSuperview]; 
      black = nil; 
      splash = nil; 
      self.view.userInteractionEnabled = YES; 

     }]; 
    }]; 

}); 


} 

내가 탐색 컨트롤러 또는 탭보기 컨트롤러가 애플 리케이션이 코드를 테스트하지 않은 있지만 일반 뷰 컨트롤러와 매력처럼 작동합니다.

+0

고마워, 나는 오늘 밤 이것을 시도 할 것이다! –