2010-06-16 3 views
1

J'ai créé une vue que je souhaite pouvoir faire pivoter. Les deux vues sont: containerView et cela a un .backgroundColor de rouge et BackgroundImage comme sous-vue. Voici mon code pour faire tourner:iOS - La vue en rotation révèle l'arrière-plan

- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 
    [self adjustViewsForOrientation:toInterfaceOrientation]; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    return YES; 
} 

- (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation { 
if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) { 
    backgroundImage.image = [UIImage imageNamed:@"landscape.jpg"]; 
    backgroundImage.frame = CGRectMake(0, 0, 1024, 704); 
    containerView.frame = CGRectMake(0, 0, 1024, 704); 
    self.title = @"landscape"; 
    } else if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) { 
    backgroundImage.image = [UIImage imageNamed:@"portrait.jpg"]; 
    backgroundImage.frame = CGRectMake(0, 0, 768, 960); 
    containerView.frame = CGRectMake(0, 0, 768, 960); 
    self.title = @"portrait"; 
    } 
} 

Le problème est que l'image tourne, mais la couleur d'arrière-plan est affichée pendant la rotation de la vue. Y a-t-il une bonne solution à ce problème (je sais que je pourrais créer les images à mélanger dans une couleur et mettre l'arrière-plan à la même couleur, mais ce n'est pas ce que je voudrais).

Une vidéo du problème peut être vu ici: http://tinypic.com/r/2quj24g/6

PS les images sont de la OmniGroup GitHub repo et ne sont utilisées pour la démo.

Répondre

2

La solution à ce problème consiste à définir les UIView ou UIWindow backgroundColor à [UIColor blackColor]. Lorsque vous faites pivoter Safari, la même chose se produit exactement, juste la couleur de fond est noire, comme il devrait normalement l'être. Toutes les applications sur l'iPad tournent de cette façon, et l'utilisateur ne remarquera aucune différence.

PS- Au lieu d'utiliser la méthode willRotateToInterfaceOrientation:duration:, utilisez willAnimateRotationToInterfaceOrientation:duration:

0

Vous pouvez rendre votre image plus grande que la taille de l'écran. Ainsi, sur l'iphone, faites l'image 480 x 480. Ou dans votre cas, 1024 x 1024.

Questions connexes