Какой метод определяет поворот устройства из портретного в ландшафтный режим - PullRequest
0 голосов
/ 19 сентября 2009

У меня есть этот метод, но где я должен положить этот метод ???

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

// This method is called by NSNotificationCenter when the device is rotated.
-(void) receivedRotate: (NSNotification*) notification
{
    UIDeviceOrientation interfaceOrientation = [[UIDevice currentDevice] orientation];
    if(interfaceOrientation != UIDeviceOrientationUnknown)
        [self deviceInterfaceOrientationChanged:interfaceOrientation];
}

Ответы [ 2 ]

1 голос
/ 19 сентября 2009

Зависит от того, что вы пытаетесь сделать. Если вы просто хотите изменить ориентацию ваших представлений, чтобы они соответствовали устройству, то реализуйте willRotateToInterface и shouldAutorotateToInterfaceOrientation в вашем viewController. Это намного проще, чем все остальное. В случае mustAutorotateToInterfaceOrientation вы должны вернуть YES для каждой ориентации, которую вы готовы принять. Вот как выглядит процедура:

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || 
            (interfaceOrientation == UIInterfaceOrientationLandscapeRight));
}
0 голосов
/ 19 сентября 2009
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...