2012-03-25 8 views
2
私はUIのレイアウトを変更することについての学習いじりだ

時にiPhone上のデバイスの向きが変わると、私はこの問題に遭遇しました。..イメージビューには、デバイスの向きの変化に消える - iPhone - Objective Cの

Iマスターディテールアプリケーションを持っていますが、ディテールビューのときにオリエンテーションを変更するとすべて正常に動作しますが、マスタービューコントローラでそれを変更して詳細ビューをプッシュすると、画像ビュー以外はすべて動作します表示..ここ

は、関連するコードです:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 

    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; 
    if (UIDeviceOrientationIsLandscape(orientation)){ 
     [self layoutLandscape]; 
    } 
    else if (UIDeviceOrientationIsPortrait(orientation)){ 
     [self layoutPortrait]; 
    } 

    //set up UI elements 
    nameLabel.text = name; 
    dateOfBirthLabel.text = dateOfBirth; 
    numberOfVotesLabel.text = numberOfVotes; 
    reasonForFameLabel.text = reasonForFame; 
    numberOfStarsLabel.text = numberOfStars; 
    [indicator startAnimating]; 
    //Perform this method in background (gets the product image from URL) 
    [self performSelectorInBackground:@selector(loadImage) withObject:nil]; 

    //Gives UIImageView memeThumb a orange border 
    //Must import the QuartsCore Framework for this to work 
    [imageView.layer setBorderColor: [[UIColor blackColor] CGColor]]; 
    [imageView.layer setBorderWidth: 2.0]; 
} 

- (void) layoutLandscape{ 
    imageView.frame = CGRectMake(20, 20, 200, 150); 
    indicator.frame = CGRectMake(150, 40, 20, 20); 

    nameMarker.frame = CGRectMake(70, 115, 51, 150); 
    dateOfBirthMarker.frame = CGRectMake(20, 135, 101, 180); 
    numberOfVotesMarker.frame = CGRectMake(233, 10, 134, 30); 
    reasonForFameMarker.frame = CGRectMake(230, 60, 137, 30); 
    numberOfStarsMarker.frame = CGRectMake(236, 110, 130, 30); 

    nameLabel.frame = CGRectMake(125, 175, 135, 30); 
    dateOfBirthLabel.frame = CGRectMake(125, 210, 135, 30); 
    numberOfVotesLabel.frame = CGRectMake(372, 10, 134, 30); 
    reasonForFameLabel.frame = CGRectMake(372, 60, 135, 30); 
    numberOfStarsLabel.frame = CGRectMake(372, 110, 135, 30); 
} 

- (void) layoutPortrait{ 
    imageView.frame = CGRectMake(20, 20, 280, 197); 
    indicator.frame = CGRectMake(150, 109, 20, 20); 

    nameMarker.frame = CGRectMake(106, 225, 51, 30); 
    dateOfBirthMarker.frame = CGRectMake(56, 263, 101, 30); 
    numberOfVotesMarker.frame = CGRectMake(23, 301, 134, 30); 
    reasonForFameMarker.frame = CGRectMake(20, 339, 137, 30); 
    numberOfStarsMarker.frame = CGRectMake(27, 377, 130, 30); 

    nameLabel.frame = CGRectMake(165, 225, 135, 30); 
    dateOfBirthLabel.frame = CGRectMake(165, 263, 135, 30); 
    numberOfVotesLabel.frame = CGRectMake(165, 301, 134, 30); 
    reasonForFameLabel.frame = CGRectMake(165, 339, 135, 30); 
    numberOfStarsLabel.frame = CGRectMake(165, 377, 135, 30); 
} 

- (void) loadImage { 
    NSURL *imageURL = [NSURL URLWithString:URL]; 
    NSData *data = [NSData dataWithContentsOfURL:imageURL]; 
    UIImage *image = [UIImage imageWithData:data]; 
    imageView.image = image; 
    [indicator stopAnimating]; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); 
} 

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{ 
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; 
    if (UIDeviceOrientationIsLandscape(orientation)) { 
     [self layoutLandscape]; 
    } 
    else if (UIDeviceOrientationIsPortrait(orientation)) { 
     [self layoutPortrait]; 
    } 
} 

誰もがアイデアを持っていますか?

答えて

3

ビューが既に作成され、メモリに常駐している場合、viewDidLoadは呼び出されません。

-(void) viewWillAppear 
{ 
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; 
    if (UIDeviceOrientationIsLandscape(orientation)){ 
     [self layoutLandscape]; 
    } 
    else if (UIDeviceOrientationIsPortrait(orientation)){ 
     [self layoutPortrait]; 
    } 
} 
にコードを移動してみてください
関連する問題