一旦用户旋转到横向,我就会加载一个视图,但是当我在 viewDidLoad 中使用 view.bounds 时,它仍然是纵向的。
这是我加载从通知触发的视图的代码
- (void)orientationChanged:(NSNotification *)notification
{
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
if (UIDeviceOrientationIsLandscape(deviceOrientation) && !isShowingLandscapeView)
{
[self presentModalViewController:self.graphViewController animated:YES];
isShowingLandscapeView = YES;
} else if (deviceOrientation == UIDeviceOrientationPortrait && isShowingLandscapeView)
{
[self dismissModalViewControllerAnimated:YES];
isShowingLandscapeView = NO;
}
}
在 viewDidLoad 的 graphViewController 中,我使用 self.view.bounds 来初始化核心图。
这是它的样子
关于如何解决这个问题的任何提示?
非常感谢
编辑
在 viewDidLoad
// Create graph from theme
graph = [[CPTXYGraph alloc] initWithFrame:self.view.bounds];
CPTTheme *theme = [CPTTheme themeNamed:kCPTDarkGradientTheme];
[graph applyTheme:theme];
CPTGraphHostingView *hostingView = [[CPTGraphHostingView alloc] initWithFrame:self.view.bounds];
hostingView.collapsesLayers = NO; // Setting to YES reduces GPU memory usage, but can slow drawing/scrolling
hostingView.hostedGraph = graph;
[self.view addSubview:hostingView];