2010-12-07 12 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

Aha。独自のスプラッシュ画面を表示する場合は、既に行っている特殊なビューコントローラを作成する必要があります。私はあなたがオートローテーションクエリのコードを簡素化することができると思います。

- (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); 
} 

は、あなたが別のファイルにこれらを詰め込むことができますと呼ばれる2つのユーティリティの機能があります。そうならば、あなたはこのような何かを行うことができますより簡単な解決法で

1

向きを固定している場合、defult.pngの解像度はアプリの向きに影響します。

たとえば、1024x768のスプラッシュイメージが使用され、初期表示でオリエンテーションロックによるポートレート表示がサポートされていない場合、ビューが試行して表示するように視覚的UIオブジェクトが画面外(特にアニメーションが含まれる)たとえ装置がランドスケープにあっても、それ自体はポートレート構成である。

一般に、1024x768の画像は、ポートレートを意味し、768x1024の画像は、風景を意味します。

これで十分でない場合や、初期デフォルト画像からログイン画面などにシームレスに移行したい場合は、ビューコントローラーを使用してスプラッシュを続行できます。

ウィンドウにロードし、すべての通常viewControllersを、そして(ImageViewController上)右の画像を設定するshouldAutorotateToInterfaceOrientationメソッドを使用して、あなたのsplashControllerで、その後にあなたの「スプラッシュ」の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); 
} 

の設定私が使用した画像はあなたに合わないかもしれないので、いくつかの実験が必要かもしれません。これまでのところ、このソリューションを愛して - あなたは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]; 
} 
関連する問題