Для моего приложения требуется, чтобы UIViews были осведомлены о ротации.IPad вращение: Первое событие вращения не уведомлено?
Когда мое приложение запускается, оно получает UIApplicationWillChangeStatusBarOrientationNotification
.
Затем, однако, при самом первом вращении (с ориентацией на любую ориентацию) получение уведомления не производится.
Каждое последующее событие вращения генерирует ожидаемое уведомление UIApplicationWillChangeStatusBarOrientationNotification
.
То же самое относится к уведомлениям UIDeviceOrientationDidChangeNotification
, когда код для изменения ориентации устройства изменен, код - идентичные результаты.
Код: (myUIView INIT)
// set up to listen for rotation
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didRotate)
name:UIApplicationDidChangeStatusBarOrientationNotification
object:nil];
(myUIView на вращение)
-(void)didRotate
{
if ([self landscape]) // rotated TO landscape
{
// do landscape stuff
}
}
(проверка вращения в myUIView)
// answer the question: are we landscape? Yes or no. No indicates portrait.
-(BOOL)landscape
{
UIInterfaceOrientation iOrientation = [UIApplication sharedApplication].statusBarOrientation;
// Just get a displayable string version
NSString* iOrientationString ;
switch (iOrientation) {
case UIInterfaceOrientationPortrait : iOrientationString = @"UIInterfaceOrientationPortrait" ; break ;
case UIInterfaceOrientationPortraitUpsideDown : iOrientationString = @"UIInterfaceOrientationPortraitUpsideDown" ; break ;
case UIInterfaceOrientationLandscapeLeft:iOrientationString = @"UIInterfaceOrientationLandscapeLeft" ; break ;
case UIInterfaceOrientationLandscapeRight:iOrientationString = @"UIInterfaceOrientationLandscapeRight " ; break ;
}
NSLog(@"%@=%@" , @S(iOrientation) , iOrientationString) ;
return UIInterfaceOrientationIsLandscape(iOrientation);
}
Хочу отметить, что в UIViewController
, -(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
правильно вызывается, первое вращение и все ,
Но я хотел бы иметь виды с поддержкой вращения. Есть ли объяснение и/или обходной путь для этого отсутствующего первого события?
положить [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; в applicationdidFinishLaunchingWithOptions или поместить его в awakefromnib. – Maruti
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; в applicationdidFinishLaunchingWithOptions или awakefromnib - это либо сторона, где она есть (первая строка моего опубликованного кода. Разве это будет иметь огромное значение? Вспомните, что это IS (вид) работает - просто отсутствует первое событие. –