5

スプラッシュ スクリーンは機能していますが、アプリは横向きモードで動作し、スプラッシュ スクリーンはデフォルトの縦向きモードで表示されます。

アプリのようにスプラッシュ スクリーンがランドスケープ モード間で回転するようにアプリを起動するにはどうすればよいですか?

私は次のコードを使用しています:

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

しかし、回転を表示画面内に配置するにはどうすればよいですか?

4

4 に答える 4

4

あはは。独自のスプラッシュ スクリーンを表示する場合は、そのための特別なビュー コントローラーを作成する必要があります。これは既に行っています。自動回転クエリ コードを簡略化できると思います。

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

ここで、さまざまな向きのスプラッシュ スクリーンについて考える必要があります。横向きと縦向きで別々のスプラッシュ画像はありますか? はいの場合、次のようなことができます。

- (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 つのユーティリティ関数があり、これらを別のファイルに詰め込むことができます。

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

少し面倒です。もっと簡単な解決策に興味があります。

于 2010-12-07T10:32:40.000 に答える
3

@zoul - これまでのところ、このソリューションが大好きです。ただし、そのビューにサブビューがある場合は、表示されません。何か案は?

アップデート:

-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];
}
于 2010-12-22T00:17:30.120 に答える
1

向きをロックしている場合、defult.pngの解像度がアプリの向きに影響を与える可能性があります。

たとえば、1024x768のスプラッシュ画像が使用され、初期ビューが向きのロックによる縦向きの表示をサポートしていない場合、ビューが縦向きで表示されようとするため、ビジュアルUIオブジェクトが画面外に表示される可能性があります(特にアニメーションが含まれる場合)。デバイスがランドスケープにある場合でも、構成。

一般に、1024x768の画像は縦向きを意味し、768x1024の画像は横向きを意味します。

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

すべての通常のviewControllerをウィンドウにロードしてから、「splash」viewControllerをsplashController useshouldAutorotateToInterfaceOrientationメソッドに配置して、適切な画像を(ImageViewController上に)設定します。

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

私が使用した画像の構成はあなたに合わないかもしれないので、いくつかの実験が必要かもしれません。

于 2010-12-07T10:53:23.400 に答える
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

    }

メソッドに YES を返す必要があることに注意してくださいshouldAutorotateToInterfaceOrientation:

于 2010-12-13T07:27:26.837 に答える