Question

Mon écran d'accueil fonctionne, mais mon application fonctionne en mode paysage, et l'écran affiche de démarrage en mode portrait par défaut.

Comment puis-je commencer l'application de telle sorte que la rotation de l'écran d'accueil entre les modes paysage comme mon application?

J'utilise le code suivant:

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

et l'écran de démarrage

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

Mais comment puis-je mettre la rotation à l'intérieur de l'écran d'affichage?

Était-ce utile?

La solution

@zoul - aimer cette solution jusqu'à présent. Toutefois, si / quand ce point de vue a des sous-vues - ils ne se présentent pas. toutes les idées?

Mise à jour:

résolu ce problème en ajoutant un sous-vue au UIView créé dans -startupImageWithOrientation: pas self.view.

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

Autres conseils

Aha. Si vous voulez afficher votre propre écran de démarrage, vous devez créer un contrôleur spécial de vue pour ce qui vous l'avez déjà fait. Je pense que vous pouvez simplifier le code de requête autorotation:

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

Maintenant, vous devez penser à les écrans de démarrage pour des orientations différentes. Avez-vous une image de démarrage séparée pour le paysage et le portrait? Si oui, vous pouvez faire quelque chose comme ceci:

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

Il existe deux fonctions utilitaires appelées, vous pouvez farcir ceux-ci dans un fichier séparé:

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

Il est un peu salissante, je serais intéressé par moi-même solution plus simple.

La résolution de votre defult.png peut affecter votre orientation des applications si vous avez des orientations verrouillées.

Par exemple, si une image 1024x768 de démarrage est utilisé et la vue initiale ne prend pas en charge portrait regardant à travers l'orientation ce verrou peut provoquer des objets interface utilisateur visuelle apparaître hors de l'écran (en particulier lorsque l'animation est impliqué) que la vue essaiera de présenter lui-même dans une configuration portrait, même si le dispositif peut être dans le paysage.

En général, 1024x768 images impliquent portrait tout en 768x1024 images impliquent le paysage.

Si cela ne suffit pas, ou votre désir d'aller en toute transparence de l'image par défaut initiale dans l'écran une connexion par exemple, vous pouvez utiliser un viewcontroller pour « continuer » les éclaboussures.

Charger toutes les viewControllers normales dans la fenêtre, puis mettez votre « splash » viewController en alors dans votre méthode splashController utilisation de shouldAutorotateToInterfaceOrientation pour définir l'image de droite (sur un 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);
}

La configuration des images que je l'ai utilisé peut ne pas vous convenir, donc un peu d'expérimentation peut être nécessaire.

- (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

    }

Notez que vous devez retourner OUI la méthode shouldAutorotateToInterfaceOrientation:

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top