2013-06-21 4 views
1

У меня есть этот кусок кода:UIScollview и выравнивание UIView странно

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

Я ожидал увидеть это:

enter image description here

Но вместо этого я вижу это:

enter image description here

Я получаю ожидаемое от нового проекта, используя только uiview и приведенный выше код, используя какао-контроль FDGraphView (кстати, это здорово), я получаю странное поведение.

FDGraphView является UIView подкласс, но использует UIScrollView также и работает нормально при добавлении как подвид в представлении ViewController,

любые идеи ??

Edit: Видимо что-то в коде ниже вызывает проблему

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

} 
` 
+1

Вы используете Autolayout или пружины и стойки, которые могут вызывать разницу между двумя проектами? – iwasrobbed

+0

К сожалению, нет, я даже добавил класс FDGraph к новому проекту, и он работает нормально, как и ожидалось ... действительно раздражает - мне интересно, что с ним происходит! – Woodstock

+0

Ок, видимо, что-то в этом кодексе вызывает проблему! – Woodstock

ответ

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

были вызваны делегатом, перемещающим рамку моего графика. МЭН! Глупый действительно ...

Смежные вопросы