1

一旦用户旋转到横向,我就会加载一个视图,但是当我在 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];
4

2 回答 2

3

假设CPTGraphHostingView将调整其呈现方式的方向,您需要在其autoresizingMask上进行设置。这决定了视图在其超级视图调整大小时如何调整大小,这在这种情况下正在发生。

hostingView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
于 2011-09-21T16:39:43.480 回答
0

It's not the correct approach. You should be doing this stuff in layoutSubviews. It will be called first time in, and subsequently each time orientation changes. Do something like this:

- (void)layoutSubviews 
{
    [super layoutSubviews];
    CGRect frame = self.bounds;

    // Do your subviews layout here based upon frame
}
于 2011-09-21T16:37:14.777 回答