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

それは正しいアプローチではありません。このようなことはlayoutSubviewsで行う必要があります。初めて呼び出され、その後、向きが変わるたびに呼び出されます。このようなことをします:

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

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