Запустить приложение в PortraitUpsideDown дает проблемы с переводом - PullRequest
0 голосов
/ 14 марта 2011

У меня есть несколько изображений в поле зрения.При вращении мои изображения размещаются правильно с помощью CGAffineTransformTranslate & Rotate.

Однако, когда я запускаю в PortraitUpsidedown, происходит перевод, который я определил с помощью метода

"- (void) willRotateToInterfaceOrientation: (UIInterfaceOrientation) toInterfaceOrientation duration: (NSTimeInterval) duration {".

Этот перевод должен осуществляться только при изменении ориентации устройства.Как я могу убедиться, что этот перевод не произойдет при запуске?

РЕДАКТИРОВАТЬ:

Все еще возникли проблемы после вашего совета по реализации метода viewWillAppear.

Вот код моего проекта.

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {

    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];

    if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
       toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {

        image1.transform = CGAffineTransformTranslate( image1.transform, -65.0, 255.0);
        image2.transform = CGAffineTransformTranslate( image2.transform, -65.0, 255.0);
    }
    else {

        image1.transform = CGAffineTransformIdentity;
        image2.transform = CGAffineTransformIdentity;
    }

}

-(void) viewWillAppear:(BOOL)isRotated{

    isRotated = FALSE;
}

Но как мне реализовать фрагмент кода, в котором я определяю

isRotated = TRUE;

Спасибо за вашу помощь!

1 Ответ

0 голосов
/ 14 марта 2011

Используйте метод делегата shouldAutorotateToInterfaceOrientation:

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Overriden to allow any orientation.
    return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight));
}

Установить переменную BOOL. Сделайте это YES, когда интерфейс соответствует тому, что нам нужно было использовать CGAffineTransformTranslate & rotate, или вызовите метод оттуда для перевода:

как:

if (interfaceOrientation == UIInterfaceOrientationLandscapeRight) 
    // do something
...