Iphone 边界何时更新?

Iphone 边界何时更新?,iphone,viewdidload,bounds,Iphone,Viewdidload,Bounds,当用户旋转到横向时,我正在加载视图,但当我在viewDidLoad中使用view.bounds时,它仍处于纵向 这里是我加载视图的代码,该视图是由通知触发的 - (void)orientationChanged:(NSNotification *)notification { UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation; if (UIDeviceOrientationIs

当用户旋转到横向时,我正在加载视图,但当我在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];

这不是正确的方法。您应该在LayoutSubView中执行这些操作。它将在中第一次调用,随后每次方向更改时调用。这样做:

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

    // Do your subviews layout here based upon frame
}

假设
CPTGraphHostingView
将调整其渲染方式的方向,则需要在其上设置
autoresizingMask
。这决定了当视图的超级视图调整大小时,视图如何调整大小,在本例中就是如此

hostingView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);

如何在屏幕上添加图形视图?您正在尝试将其直接添加到窗口吗?[self-presentModalViewController:self.graphViewController动画:是];是的,但在该视图控制器中,如何创建和添加图形视图。请显示更多代码。很明显,视图控制器正在正确旋转,因此其子视图也应该正确旋转。我不确定我是否正确理解您的意思。我在viewDidLoad中添加了一些代码,在那里我创建了一个GraphHostingView并将其添加到self.view的子视图中。鉴于
CPTGraphHostingView
是Core Plot的一部分,一个静态库,我不确定这是一个理想的解决方案,因为它需要修改库。相反,假设自动调整大小的遮罩不能按预期工作,视图控制器的旋转方法将更适合调整图形视图的框架。应该是自动调整大小的遮罩,但你就是那个人!那很好用。非常感谢!(:)但我很高兴你得到了它!