0

Mon application est prise en charge uniquement en mode Portrait. J'ai l'exigence que besoin de faire pivoter le UIView seulement en fonction de l'orientation de l'appareil.Faire pivoter la vue uniquement dans ios

Pouvez-vous s'il vous plaît aidez-moi?

+0

Que voulez-vous dire par UIView seul? – ezcoding

+0

affichage seulement ... pas une vueController –

+0

Avez-vous besoin de faire pivoter la vue, lorsque l'orientation de votre appareil change? – ezcoding

Répondre

0

Après le long essai que j'ai trouvé la réponse en utilisant CGAffineTransform ..

- (void)deviceOrientationDidChange:(NSNotification *)notification { 
    //Obtain current device orientation 
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; 

    CGFloat angle; 
    switch (orientation) { 
     case UIDeviceOrientationPortraitUpsideDown: 
      angle = M_PI; 
      break; 
     case UIDeviceOrientationLandscapeRight: 
      angle = - M_PI_2; 
      break; 
     case UIDeviceOrientationLandscapeLeft: 
      angle = M_PI_2; 
      break; 
     case UIDeviceOrientationPortrait: 
     default: 
      angle = 0.f; 
      break; 
    } 
    animationView.transform= CGAffineTransformMakeRotation(angle); 
    animationView.frame = self.view.frame; 
} 
0

Ajouter ci-dessous donne le code dans votre viewDidLoad INIT ou

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 

[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(deviceOrientationDidChange:) name: UIDeviceOrientationDidChangeNotification object: nil]; 

En fonction deviceOrientationDidChange vous obtiendrez l'orientation de l'appareil, selon ce que vous pouvez mettre à jour votre vue

- (void)deviceOrientationDidChange:(NSNotification *)notification { 
    //Obtain current device orientation 
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; 

     //Do my thing 
} 
+0

merci. C'est ce que j'ai fait. J'ai besoin de faire pivoter la vue en fonction de l'orientation de l'appareil. –

+0

@YanoRatheez: CGAffineTransform transform = CGAffineTransformMakeRotation (angle); [yourView setTransform: transformer]; Réglez ici l'angle correspondant à l'orientation de votre appareil. –

+0

si cela vous aide s'il vous plaît accepter la réponse .. :) –

0
if (interfaceOrientation == UIInterfaceOrientationPortrait) { 
    // set your view frame work for portrait mode 

} 
else { 
// set new frame of view for landscape mode. 
} 

Espoir vous avoir l'idée. grâce

+0

Désolé ... Je n'ai pas obtenu cela .. Je dois tourner la vue en utilisant seulement CGAffineTransform ou un autre. –