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];

我希望看到这个:

在此处输入图像描述

但相反,我看到了这个:

在此处输入图像描述

我只使用 uiview 和上面的代码,使用可可控件 FDGraphView (顺便说一句很棒),我得到了一个新项目的预期,我得到了奇怪的行为。

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

在这段代码中:

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)];

    }

}

代码行:

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

被移动我的graphView框架的代表调用!真是傻...

于 2013-06-21T21:27:44.020 回答