Мое приложение будет запущено в Пейзаж, только один вид может измениться на портрет, в котором есть кнопка, я нажимаю эту кнопку, чтобы изменить ориентацию на портрет. Он выполнялся так, как ожидалось, на iPad (iOS 8.4, цель развертывания: 7.0), и я сделал версию для iPhone, в которой я только что настроил пользовательский интерфейс, и он работает на симуляторе iPhone 6 Plus (Base SDK: 9.1, Цель развертывания : 7.0), но кнопка для ориентации чата не работает. И я хочу знать, как реализовать это в iOS 9; Внизу мой код:Изменить ориентацию в iOS 9
- (void)changeOrientation
{
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if(orientation==UIInterfaceOrientationLandscapeLeft||orientation==UIInterfaceOrientationLandscapeRight){
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
if (orientation==UIInterfaceOrientationLandscapeLeft) {
value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
}else {
value = [NSNumber numberWithInt:UIInterfaceOrientationPortraitUpsideDown];
}
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
[[NSNotificationCenter defaultCenter] postNotificationName:@"ScreenToPortrait" object:nil];
}else{
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
if (orientation==UIInterfaceOrientationPortrait) {
value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
}else {
value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight];
}
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
[[NSNotificationCenter defaultCenter] postNotificationName:@"ScreenToLandscapeLeft" object:nil];
}
[UIViewController attemptRotationToDeviceOrientation];
}