我有一个简单的 IPAD 结构,其中包含来自 viewController 的视图的 AppDelegate:
- (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)调整大小以占据整个屏幕。
为什么 ??我想保持初始大小。
这里是我的问题的截图。旋转前:
旋转后: