2012-06-17 6 views
3

У меня возникли проблемы с моим UIViews в зависимости от ориентации устройства ...обработки ИОС ориентации устройства

Основной вопрос, который я имею что

UIDeviceOrientationFaceUp 
UIDeviceOrientationFaceDown 

перепутали мой взгляд, я только хочу для поддержки портретной и альбомной ориентации (слева направо), поэтому, если устройство меняет ориентацию, мой взгляд изменяет себя правильно.

Это то, что я реализовал в данный момент. В основном это UIView, который прокручивается из нижней части экрана и имеет несколько кнопок в этом представлении, что пользователь может выбрать для загрузки другого представления.

#pragma jumpBarButtons 
- (void)jumpBarButtonPosition 
{ 

    //orientation stuff 
    if (jumpBar.isViewLoaded) { 

     UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; 


     switch (orientation) { 
      case UIDeviceOrientationPortrait: 
      { 
       NSLog(@"Portrait"); 

       // Row one 
       jumpButton1.frame = CGRectMake(18.45, 23.0, 57.0, 57.0); 
       jumpButton2.frame = CGRectMake(93.9, 23.0, 57.0, 57.0); 
       jumpButton3.frame = CGRectMake(169.35, 23.0, 57.0, 57.0); 
       jumpButton4.frame = CGRectMake(244.8, 23.0, 57.0, 57.0); 
       // Row tow 
       jumpButton5.frame = CGRectMake(18.45, 95.0, 57.0, 57.0); 
       jumpButton6.frame = CGRectMake(93.9, 95.0, 57.0, 57.0); 
       jumpButton7.frame = CGRectMake(169.35, 95.0, 57.0, 57.0); 
       jumpButton8.frame = CGRectMake(244.8, 95.0, 57.0, 57.0); 
       // Row three 
       jumpButton9.frame = CGRectMake(18.45, 167.0, 57.0, 57.0); 
       jumpButton10.frame = CGRectMake(93.9, 167.0, 57.0, 57.0); 
       jumpButton11.frame = CGRectMake(169.35, 167.0, 57.0, 57.0); 
       jumpButton12.frame = CGRectMake(244.8, 167.0, 57.0, 57.0); 
       // Row four 
       jumpButton13.frame = CGRectMake(18.45, 239.0, 57.0, 57.0); 
       jumpButton14.frame = CGRectMake(93.9, 239.0, 57.0, 57.0); 
       jumpButton15.frame = CGRectMake(169.35, 239.0, 57.0, 57.0); 
       jumpButton16.frame = CGRectMake(244.8, 239.0, 57.0, 57.0); 
      } 
       break; 

case UIDeviceOrientationLandscapeLeft: 
      case UIDeviceOrientationLandscapeRight: 
      { 
       viewSpaceHeight = 207; 
       viewSpaceWidth = 480; 

       // Row one 
       jumpButton1.frame = CGRectMake(19.7, 9.0, 57.0, 57.0); 
       jumpButton2.frame = CGRectMake(96.42, 9.0, 57.0, 57.0); 
       jumpButton3.frame = CGRectMake(173.13, 9.0, 57.0, 57.0); 
       jumpButton4.frame = CGRectMake(249.84, 9.0, 57.0, 57.0); 
       jumpButton5.frame = CGRectMake(326.55, 9.0, 57.0, 57.0); 
       jumpButton6.frame = CGRectMake(403.26, 9.0, 57.0, 57.0); 
       // Row tow 
       jumpButton7.frame = CGRectMake(19.7, 75.0, 57.0, 57.0); 
       jumpButton8.frame = CGRectMake(96.42, 75.0, 57.0, 57.0); 
       jumpButton9.frame = CGRectMake(173.13, 75.0, 57.0, 57.0); 
       jumpButton10.frame = CGRectMake(249.84, 75.0, 57.0, 57.0); 
       jumpButton11.frame = CGRectMake(326.55, 75.0, 57.0, 57.0); 
       jumpButton12.frame = CGRectMake(403.26, 75.0, 57.0, 57.0); 
       // Row three 
       jumpButton13.frame = CGRectMake(19.7, 141.0, 57.0, 57.0); 
       jumpButton14.frame = CGRectMake(96.42, 141.0, 57.0, 57.0); 
       jumpButton15.frame = CGRectMake(173.13, 141.0, 57.0, 57.0); 
       jumpButton16.frame = CGRectMake(249.84, 141.0, 57.0, 57.0); 

      } 
       break; 
//.. 

тот довольно много, если в портрете есть 16 4,4,4,4 иконки, если пейзаж, то иконки 6,6,4. что произойдет, если устройство перевернуто лицевой стороной вверх или вниз, все эти кнопки исчезнут. Что я могу сделать, чтобы остановить это, любая помощь будет оценена по достоинству.

ответ

3

Используйте вместо этого UIInterfaceDirection. Его часть UIApplication класса и содержит только следующие значения

typedef enum { 
    UIInterfaceOrientationPortrait   = UIDeviceOrientationPortrait, 
    UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown, 
    UIInterfaceOrientationLandscapeLeft  = UIDeviceOrientationLandscapeRight, 
    UIInterfaceOrientationLandscapeRight  = UIDeviceOrientationLandscapeLeft 
} UIInterfaceOrientation; 

Вы можете легко проверить текущую ориентацию, как это:

[[UIApplication sharedApplication] statusBarOrientation] 
+0

аааа отлично! спасибо очень много .. Я, хотя я сошел с ума на секунду! :П – HurkNburkS

Смежные вопросы