Подтвердить что ты не робот

Поддержка как авторизованных iOS 6, так и iOS 5

Может ли кто-нибудь подтвердить, что для поддержки iOS 6 и iOS 5 нет смысла добавлять новые методы авторотации iOS 6, поскольку документы Apple предлагают, чтобы эти методы полностью игнорировались, если вы также применяете методы iOS 5?

В частности, я говорю о методах - (NSUInteger)supportedInterfaceOrientations и - (BOOL) shouldAutorotate - что они игнорируются и синтезируются компилятором, если вы также реализуете - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

4b9b3361

Ответ 1

Вам нужно добавить новый обратный вызов для авторотации, если вы упаковываете свое приложение в новый sdk. Однако эти обратные вызовы будут получены только тогда, когда такое приложение будет запущено на устройствах iOS 6. Для устройств, работающих на более ранних версиях iOS, будут получены более ранние обратные вызовы. Если вы не выполняете новые обратные вызовы, поведение по умолчанию заключается в том, что ваше приложение работает со всей ориентацией на iPad и все, кроме ориентации UpsideDown на iPhone.

Ответ 2

Для вращения iOS5. Проверьте желаемую ориентацию и верните YES.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{  
    if ((interfaceOrientation==UIInterfaceOrientationPortrait)||(interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown)) {
        return YES;
    }
    else return NO;
}

Поддержка авторотации iOS 6.0

- (BOOL)shouldAutorotate
{
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationIsPortrait(UIInterfaceOrientationMaskPortrait|| UIInterfaceOrientationMaskPortraitUpsideDown);

}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationIsPortrait(UIInterfaceOrientationPortrait|| UIInterfaceOrientationPortraitUpsideDown);

}

Ответ 3

 - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationMaskAll;
}

-(void)viewWillLayoutSubviews
{
if([self interfaceOrientation] == UIInterfaceOrientationPortrait||[self interfaceOrientation] ==UIInterfaceOrientationPortraitUpsideDown)
    {
       if (screenBounds.size.height == 568)
        {
          //set the frames for 4"(IOS6) screen here
         }
        else

        {
         ////set the frames for 3.5"(IOS5/IOS6) screen here
        }

}
        else if ([self interfaceOrientation] == UIInterfaceOrientationLandscapeLeft||[self interfaceOrientation] == UIInterfaceOrientationLandscapeRight)
        {
         if (screenBounds.size.height == 568)
        {
          //set the frames for 4"(IOS6) screen here
         }
        else

        {
         ////set the frames for 3.5"(IOS5/IOS6) screen here
        }


    }
//it is for IOS5
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
     return YES;
    }

- (void) viewWillLayoutSubviews, этот метод вызовет ios5/ios6. этот код полезен для ios6/ios5/ios6 с экраном 3,5 "экрана/4" с ios6.

Ответ 4

Я думаю, самое элегантное решение:

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    return ((1 << toInterfaceOrientation) & self.supportedInterfaceOrientations) != 0;
}

Я что-то пропустил?

Ответ 5

Вы должны установить флаг где-нибудь (я верю в ваш Info.plist), который указывает, какой из двух вы используете. Если вы используете новый, вы не можете создать для iOS 5 (или, по крайней мере, он не будет работать на iOS 5). Если вы используете старый, новые методы не вызывают. Так что да, вы в значительной степени должны выбирать, какой метод вы хотите использовать, и если вы хотите поддерживать iOS 5, вы не можете использовать новые методы.

Ответ 6

для поддержки авторотации как в ios5, так и в ios6 нам нужно обеспечить обратные вызовы в случае ios6....

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(orientationChanged:) 
    name:UIDeviceOrientationDidChangeNotification object:nil];

и нам нужно вызвать

- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;

} 

-(BOOL)shouldAutoRotate{
    return YES;
  }

для ios5

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return ((toInterfaceOrientation == UIInterfaceOrientationPortrait) || (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown));
}