1

私はこのコードを持っています:

scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 170, 320, 260)];
scrollView.contentSize = CGSizeMake(960, 240);
[scrollView setPagingEnabled:YES];
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.delegate = self;
[scrollView setBackgroundColor:[UIColor redColor]];

[self.view addSubview:scrollView];


graphView = [[FDGraphView alloc] initWithFrame:CGRectMake(0, 10, 320, 240)];
[graphView setLinesColor:[UIColor whiteColor]];
[graphView setDataPointColor:[UIColor clearColor]];
[graphView setDataPointStrokeColor:[UIColor grayColor]];
[graphView setBackgroundColor:[UIColor greenColor]];

[scrollView addSubview:graphView];

私はこれを見ることを期待しています:

ここに画像の説明を入力

しかし、代わりに私はこれを見ます:

ここに画像の説明を入力

ココア コントロール FDGraphView を使用して、uiview と上記のコードだけを使用して、新しいプロジェクトで期待どおりの結果が得られます (ちなみに、これは素晴らしいことです)。奇妙な動作が発生します。

FDGraphView は UIView サブクラスですが、UIScrollView も使用し、viewController ビューのサブビューとして追加すると正常に動作します。

何か案は??

編集:明らかに、以下のコードの何かが問題を引き起こしています

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    // resize your layers based on the view’s new bounds
    [[[self.view.layer sublayers] objectAtIndex:0] setFrame:self.view.bounds];
    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
        [graphView setFrame:CGRectMake(0, 150, 480, 150)];
        [graphView setNeedsDisplay];
        [refresh setFrame:CGRectMake(5, 305, 10, 10)];

        CGRect screenRect = [[UIScreen mainScreen] applicationFrame];

        if (screenRect.size.height == 568)
        {
            //if iPhone 5+
            NSLog(@"iPhone 5+ Detected");
            [graphView setFrame:CGRectMake(0, 150, 568, 150)];
            [graphView setNeedsDisplay];
        }


    }
    if (toInterfaceOrientation == UIInterfaceOrientationPortrait)
    {
        [graphView setFrame:CGRectMake(0, 170, 320, 240)];
        [graphView setNeedsDisplay];
        [refresh setFrame:CGRectMake(5, 465, 10, 10)];
        CGRect screenRect = [[UIScreen mainScreen] applicationFrame];

        if (screenRect.size.height == 568)
        {
            //if iPhone 5+
            NSLog(@"iPhone 5+ Detected");
            [graphView setFrame:CGRectMake(0, 170, 320, 240)];
            [graphView setNeedsDisplay];
            [refresh setFrame:CGRectMake(5, 553, 10, 10)];

        }

    }
    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
    {
        [graphView setFrame:CGRectMake(0, 150, 480, 150)];
        [graphView setNeedsDisplay];
        [refresh setFrame:CGRectMake(5, 305, 10, 10)];

        CGRect screenRect = [[UIScreen mainScreen] applicationFrame];

        if (screenRect.size.height == 568)
        {
            //if iPhone 5+
            NSLog(@"iPhone 5+ Detected");
            [graphView setFrame:CGRectMake(0, 150, 568, 150)];
            [graphView setNeedsDisplay];
        }

    }
}


- (void)viewDidAppear:(BOOL)animated
{
    [self willAnimateRotationToInterfaceOrientation:[[UIApplication sharedApplication] statusBarOrientation] duration:0.5   ];

}
`
4

1 に答える 1

0

In this piece of code:

if (toInterfaceOrientation == UIInterfaceOrientationPortrait)
{
    [graphView setFrame:CGRectMake(0, 170, 320, 240)];
    [graphView setNeedsDisplay];
    [refresh setFrame:CGRectMake(5, 465, 10, 10)];
    CGRect screenRect = [[UIScreen mainScreen] applicationFrame];

    if (screenRect.size.height == 568)
    {
        //if iPhone 5+
        NSLog(@"iPhone 5+ Detected");
        [graphView setFrame:CGRectMake(0, 170, 320, 240)];
        [graphView setNeedsDisplay];
        [refresh setFrame:CGRectMake(5, 553, 10, 10)];

    }

}

The lines of code:

    [graphView setFrame:CGRectMake(0, 170, 320, 240)];
    [graphView setNeedsDisplay];

were getting called by a delegate moving the frame of my graphView! Stupid really...

于 2013-06-21T21:27:44.020 に答える