2013-12-15 3 views
0

자습서 시리즈에서 다음 scrollview를 사용 중입니다. 세로 모드에서는 정상적으로 작동하지만 프레임은 가로 모드로 스위치를 처리하지 않습니다. 이 문제를 신속하게 해결할 수 있습니까? 미리 감사드립니다.landscape 용 iOS 스크롤 뷰 적용

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    pageControlBeingUsed = NO; 
    NSString *plistFile = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@", self.displayRegion] ofType:@"plist"]; 
    self.SituationData = [NSArray arrayWithContentsOfFile:plistFile]; 

    self.singleSituation = [SituationData objectAtIndex:selectedIndexPath]; 

    self.SituationScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)]; //distinguishing between iphone 4 and 5 screen 

    self.SituationScrollView.delegate = self; 
    self.SituationScrollView.showsHorizontalScrollIndicator = NO; 
    self.SituationScrollView.pagingEnabled = YES; 
    self.SituationScrollView.backgroundColor = [UIColor clearColor]; 

    //adding to the view 
    [self.view addSubview:self.SituationScrollView]; 

    //getting the base indicator 
    int baseNum = self.selectedIndexPath ; 

    self.plistFile = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@", self.displayRegion] ofType:@"plist"]; 
    self.auswahl = [NSArray arrayWithContentsOfFile:self.plistFile]; 

    self.SituationScrollView.contentSize = CGSizeMake(self.SituationScrollView.frame.size.width *[self.auswahl count], self.SituationScrollView.frame.size.height); 

    for (NSInteger i=1; i <= [[self auswahl] count]; i++){ 

     UIImage *situationImage = [UIImage imageNamed:[NSString stringWithFormat:@"main%@", [[self.auswahl objectAtIndex:i - 1] objectForKey:@"nat_num"]]]; 
     UIImageView *situationView = [[UIImageView alloc] initWithImage:situationImage]; 

     UILabel *situationTitle = [[UILabel alloc] init]; 
     situationTitle.text = [NSString stringWithFormat:@"%@", [[self.auswahl objectAtIndex: i - 1] objectForKey:@"species"]]; 
     [situationTitle setTextColor:[UIColor blackColor]]; 
     [situationTitle setBackgroundColor:[UIColor clearColor]]; 

     UITextView *description = [[UITextView alloc] init]; 
     description.text = [NSString stringWithFormat:@"%@", [[self.auswahl objectAtIndex: i - 1] objectForKey:@"description"]]; 
     [description setTextColor:[UIColor blackColor]]; 
     [description setBackgroundColor:[UIColor clearColor]]; 
     [description setUserInteractionEnabled:NO]; 


     situationView.frame = CGRectMake((320 * (i-1)) + SIT_IMG_X, 66, 94, 87); 
     situationTitle.frame = CGRectMake((320 * (i-1)) + TOP_DATA_X, 250, 240, 14); 
     description.frame = CGRectMake((320 * (i-1)) + DESC_X, DESC_Y, DETAIL_WIDTH, 100); 


     [self.SituationScrollView addSubview:situationView]; 
     [self.SituationScrollView addSubview:situationTitle]; 
     [self.SituationScrollView addSubview:description]; 

    } 

답변

0

작은 googlefu 마이크가 viewWillAppear 방법 대신 viewDidLoad있어서, 필요에 따라 다음 UIScrollView가 나타나야에있는 UIScrollView로드 어떤 상태에 this SO thread 밝혀.

1
use a global BOOL variable 

bOOl isLandscape = NO;

while writing frames 

    situationView.frame = CGRectMake(isLandscape?0:0, isLandscape?0:0, isLandscape?320:480 , isLandscape?480:320); 

방향 방법

if(orientation == Landscape) 

{ 

isLandscape=YES; 

} 

else 

{ 

isLandscape=NO; 

} 

    situationView.frame = CGRectMake(isLandscape?0:0, isLandscape?0:0, isLandscape?320:480 , isLandscape?480:320); 

당신이

을 사용할 수 있습니다 그것은에 따라 작동합니다 샘플로 확인 다시 쓰기