2009-10-17 8 views
0

J'ai un problème de redimensionnement lors de la rotation d'un contrôleur de vue qui a deux vues que je passe d'une animation à l'autre. Le problème apparaît si je fais les étapes suivantes:iphone: rotation de la vue inversée lors de la rotation de la vue visible

  1. Faites pivoter l'appareil lors de l'affichage du tableview.
  2. Cliquez sur le bouton d'information.
  3. Faire pivoter l'appareil (InfoView apparaît étiré).
  4. Cliquez sur le bouton d'information (tableview apparaît étirée)

Il semble que le point de vue qui n'est pas ajouté à la superview ne redimensionne correctement, car il ne faisait pas partie des vues composites lorsque le dispositif a été mis en rotation. Est-il possible d'obtenir cette vue automatiquement redimensionnée correctement?

est Ci-dessous un exemple de code

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    //background image 
    backgroundImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg-app.png"]]; 
    backgroundImageView.autoresizingMask = (UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight); 
    [self.view addSubview: backgroundImageView]; 
    [backgroundImageView release]; 


    //infoView 
    aboutImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"About.png"]]; 
    aboutImageView.autoresizingMask = (UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight); 

    //tableView 
    self.tableView = [[[UITableView alloc ] initWithFrame:[[UIScreen mainScreen] bounds] style:UITableViewStylePlain] autorelease ]; 
    //set the rowHeight once for performance reasons. 
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; 
    self.tableView.rowHeight = 75; 
    self.tableView.backgroundColor = [UIColor clearColor]; 
    self.tableView.autoresizingMask = (UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight);      

    self.tableView.delegate = self; 
    self.tableView.dataSource = self; 
    self.tableView.autoresizesSubviews = YES; 

    //set the rowHeight once for performance reasons. 
    [self.view addSubview: tableView]; 
    //[tableView release]; 

    [self.view setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth];//for resizing on rotation 

    //info button 
    UIButton * infoDarkButtonType = [[UIButton buttonWithType:UIButtonTypeInfoLight] retain]; 
    infoDarkButtonType.frame = CGRectMake(0.0, 0.0, 25.0, 25.0); 
    infoDarkButtonType.backgroundColor = [UIColor clearColor]; 
    [infoDarkButtonType addTarget:self action:@selector(infoAction:) forControlEvents:UIControlEventTouchUpInside]; 
    UIBarButtonItem *buttonInfo = [[UIBarButtonItem alloc] initWithCustomView:infoDarkButtonType]; 
    self.navigationItem.rightBarButtonItem = buttonInfo; 
    [infoDarkButtonType release]; 
    self.navigationItem.rightBarButtonItem = buttonInfo; 
    [buttonInfo release]; 

} 

// Override to allow orientations other than the default portrait orientation. 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    // Return YES for supported orientations 
    return YES; 

} 


- (void)infoAction:(id)sender{ 
    NSLog(@"Clicked on the info button"); 


    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration:0.75];  /* Sub. duration here */ 

    UIView *superview; 
    if ((superview = [tableView superview])) { 
     [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:superview cache:YES]; 
     [tableView removeFromSuperview]; 
     [superview addSubview:aboutImageView]; 
    } else if ((superview = [aboutImageView superview])) { 
     [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:superview cache:YES]; 
     [aboutImageView removeFromSuperview]; 
     [superview addSubview:tableView]; 
    } 

    [UIView commitAnimations]; 
} 

Merci

Répondre

0

Essayez de mettre le code à viewWillAppear: animation. Il est appelé chaque fois que votre vue apparaîtra. La charge de vue a été appelée une fois.

+0

- (void) viewWillAppear: (BOOL) animé chaque vue l'hérite. – JoePasq

+0

De quel code parlez-vous? –

+0

le code relatif au dessin de vue et au redimensionnement automatique que vous avez ajouté à votre méthode viewDidLoad. – JoePasq

Questions connexes