Я работаю над приложением для iPhone на основе UITabBarController и UIViewControllers для каждой страницы. Приложение должно работать в режиме портрета только, таким образом, каждый контроллер представления + делегат приложения идет с этой строкой кода:
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
Существует один контроллер представления, где я хотел бы открыться UIImageView, когда iPhone является rotaed к landscapeleft. Дизайн изображения смотрит среда, хотя ширина и высота 320x460 (так ее портрет).
Как могут/должны, я обнаруживаю этот тип вращения вручную, только в этом определенном контроллере представления, withouth наличие авторотации на всем представлении?
Thomas
ОБНОВЛЕНИЕ:
Спасибо!
Я добавил этого слушателя в viewDidLoad:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:)name:UIDeviceOrientationDidChangeNotification object:nil];
didRotate похож на это:
- (void) didRotate:(NSNotification *)notification
{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIDeviceOrientationLandscapeLeft)
{
//your code here
}
}
Мне это было нужно в старом проекте - надеюсь, он все еще работает ...
1) Зарегистрируйте уведомление:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(detectOrientation)
name:UIDeviceOrientationDidChangeNotification
object:nil];
2) Затем вы можете проверить ротацию при изменении:
-(void) detectOrientation {
if (([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft) ||
([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)) {
[self doLandscapeThings];
} else if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait || [[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown) {
[self doPortraitThings];
}
}
Надеюсь, это поможет!