私はviewControllerからのビューを含むAppDelegateを備えたIPADの単純な構造を持っています:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
ClockVC *clockVC = [[ClockVC alloc]init];
clockVC.view.frame = CGRectMake(100, 100, clockVC.view.bounds.size.width, clockVC.view.bounds.size.height);
[self.window addSubview:clockVC.view];
[self.window makeKeyAndVisible];
return YES;
}
clockVCには、次のコードで定義されたviewDidLoadがあります。
- (void)viewDidLoad {
[super viewDidLoad];
self.view.autoresizingMask = UIViewAutoresizingNone;
self.view.autoresizesSubviews = UIViewAutoresizingNone;
}
clockVCの境界はIBによって定義され、application:didFinishLaunching...でオーバーライドされます。幅と高さはそれぞれ200と150です。
ClockVCは、ワンステップ自動回転のメソッドを実装します:/
/ Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
-(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
[UIView animateWithDuration:0.5
animations:^{self.view.alpha = 0;}
];
}
-(void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
[UIView animateWithDuration:1
animations:^{self.view.alpha = 1;}
];
}
最初のロード時に、ページが正しく表示され、clockVCビューが配置されます。clockVCビュー(autoResizeMaskがUIViewAutoresizingNonに設定されている)を回転すると、画面全体を表示するようにサイズが変更されます。
なぜ ??初期サイズを維持したいのですが。
ここに私の問題のスクリーンショットがあります。ローテーション前:
ローテーション後: