2010-12-07 2 views
5

내 스플래시 화면이 작동하지만 내 앱이 가로 모드로 작동하고 스플래시 화면이 기본 세로 모드로 표시됩니다.iOS에서 맞춤 시작 화면을 회전하려면 어떻게해야하나요?

스플래시 화면이 내 앱과 같은 가로 모드 사이에서 회전하도록 앱을 시작하려면 어떻게해야합니까?

나는 다음과 같은 코드를 사용하고 있습니다 :

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
// Overriden to allow any orientation. 
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || 
    interfaceOrientation == UIInterfaceOrientationLandscapeRight) 
    return YES; 
else { 
    return NO; } 
} 

및 시작 화면

-(void)displayScreen { 
UIViewController *displayViewController=[[UIViewController alloc] init]; 
displayViewController.view = displaySplashScreen; 
[self presentModalViewController:displayViewController animated:NO]; 
[self performSelector:@selector(removeScreen) withObject:nil afterDelay:3.0]; 
} 
-(void)removeScreen 
{ [[self modalViewController] dismissModalViewControllerAnimated:YES]; 
} 

를 들어하지만 어떻게 디스플레이 화면 내부의 회전을 넣을 수 있습니다?

+0

이 게시물은 Xcode와 관련이 없습니다. 그래서 나는 당신의 제목에서 그 단어를 삭제했습니다. –

+0

는 iphone 및 ipad 태그를 추가했습니다. 많은 사람들이 fav를 가지고 있기 때문에 더 많은 조회수를 얻을 수 있습니다. –

답변

3

@zoul를 반환해야

4

아하. 자신의 스플래시 화면을 표시하려면 이미 수행 한 스페셜 뷰 컨트롤러를 작성해야합니다. 난 당신이 자동 회전 쿼리 코드를 단순화 할 수 있다고 생각 :

- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) foo 
{ 
    return YES; // all interface orientations supported 
} 

는 이제 서로 다른 방향의 시작 화면에 대해 생각해야합니다. 풍경과 초상화를위한 별도의 스플래시 이미지가 있습니까?

NSString *UIInterfaceOrientationName(UIInterfaceOrientation io) 
{ 
    return UIInterfaceOrientationIsPortrait(io) ? @"Portrait" : @"Landscape"; 
} 

CGAffineTransform CGAffineTransformFromUIOrientation(UIInterfaceOrientation io) 
{ 
    assert(io <= 4); 
    // unknown, portrait, portrait u/d, landscape L, landscape R 
    static float angles[] = {0, 0, M_PI, M_PI/2, -M_PI/2}; 
    return CGAffineTransformMakeRotation(angles[io]); 
} 

그것은 조금 지저분한, 난이 관심이있을 것 :

- (UIView*) startupImageWithOrientation: (UIInterfaceOrientation) io 
{ 
    UIImage *img = [UIImage imageNamed:[NSString 
     stringWithFormat:@"Default-%@.png", UIInterfaceOrientationName(io)]]; 
    UIView *view = [[UIImageView alloc] initWithImage:img]; 
    [view setFrame:[[UIScreen mainScreen] applicationFrame]]; 
    return [view autorelease]; 
} 

- (void) loadView 
{ 
    self.view = [self startupImageWithOrientation:self.interfaceOrientation]; 
} 

- (void) willRotateToInterfaceOrientation: (UIInterfaceOrientation) io 
    duration: (NSTimeInterval) duration 
{ 
    self.view = [self startupImageWithOrientation:io]; 
    self.view.transform = CGAffineTransformFromUIOrientation(io); 
} 

, 당신은 별도의 파일로이 물건 수라는 두 개의 유틸리티 함수가 있습니다 : 예, 당신은 이런 식으로 뭔가를 할 수 더 간단한 해결책에서.

1

방향을 잠근 경우 defult.png의 해상도가 앱 방향에 영향을 줄 수 있습니다.

예를 들어 1024x768 스플래시 이미지가 사용되고 초기보기가 오리엔테이션 잠금을 통한 세로보기를 지원하지 않는 경우보기가 시도하고 표시 할 때 시각적 UI 개체가 화면 외부에 표시 될 수 있습니다 (특히 애니메이션이 포함 된 경우). 장치가 가로 방향으로있을지라도 세로 형 구성으로되어 있습니다.

일반적으로 1024x768 이미지는 세로 이미지를 의미하지만 768x1024 이미지는 가로 이미지를 의미합니다.

이것이 충분하지 않거나 초기 기본 이미지에서 로그인 화면으로 자연스럽게 이동하려는 경우 viewcontroller를 사용하여 스플래시를 계속할 수 있습니다.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    // Overriden to allow any orientation. 

switch ([[UIDevice currentDevice] orientation]) 
{ 
    case UIInterfaceOrientationLandscapeRight: 
    splashImage.image = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"Default"] ofType:@"png"]]; 
    break; 
    case UIInterfaceOrientationPortrait: 
    splashImage.image = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"Default"] ofType:@"png"]]; 
    break; 
    default: 
    splashImage.image = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"Default2"] ofType:@"png"]]; 
    break; 
} 

    return UIInterfaceOrientationIsLandscape(interfaceOrientation); 
} 

의 구성 : 창에

로드 모든 정상 viewControllers 후 (AN ImageViewController)에 오른쪽 이미지를 설정하기 위해 splashController 사용에 다음에 shouldAutorotateToInterfaceOrientation 방법을 당신의 '시작'의 ViewController를 넣어 내가 사용했던 이미지가 당신에게 어울리지 않을 수 있으므로 몇 가지 실험이 필요할 수 있습니다. 지금까지이 솔루션을 사랑 - 당신이 YES 방법 shouldAutorotateToInterfaceOrientation:

0
- (void)willAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 

    if (toInterfaceOrientation == UIInterfaceOrientationPortrait) 
    { 
     // take action here , when phone is "Portrait" 

    } 
    else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) 
    { 
     action 4 LandscapeLeft 

    } 
    else if (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) 
    { 
     //PortraitUpsideDown 

    } 
    else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) 
    { 
     //LandscapeRight 

    } 

참고. 그러나 해당보기에 하위보기가있는 경우에는 표시되지 않습니다. 어떤 아이디어?

갱신 :

-startupImageWithOrientation: 하지 self.view에서 만든 UIView의에 하위 뷰를 추가하여이 문제를 해결했습니다.

- (UIView *)startupImageWithOrientation:(UIInterfaceOrientation)io{ 
    UIImage *img = [UIImage imageNamed:[NSString stringWithFormat:@"Default-%@.png", UIInterfaceOrientationName(io)]]; 
    UIView *aView = [[UIImageView alloc] initWithImage:img]; 
    [aView setFrame:[[UIScreen mainScreen] applicationFrame]]; 

    // define the version number label 
    self.versionNumberLabel_iPadSplashScreen.text = [NSString stringWithFormat:@"Version %@", 
                      [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]]; 

    [aView addSubview:self.versionNumberLabel_iPadSplashScreen]; 

    return [aView autorelease]; 
} 
관련 문제