2009-10-17 228 views
0

旋轉具有兩個視圖的視圖控制器時,我使用翻轉動畫進行切換時發生調整大小問題。 如果我執行以下步驟,則會出現問題:iphone:在旋轉可見視圖時旋轉翻轉視圖

  1. 查看tableview時旋轉設備。
  2. 單擊信息按鈕。
  3. 旋轉設備(infoView顯示拉伸)。
  4. 點擊信息按鈕(的tableview出現拉伸)

似乎未添加到上海華視圖不會調整大小正確的,因爲該設備被旋轉時,它是沒有的合成視圖的一部分。有什麼辦法讓這個視圖自動調整大小正確?

下面是一個代碼示例

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

感謝

回答

0

嘗試把代碼viewWillAppear中:動畫。每次您的視圖出現時都會調用它。視圖確實加載被調用一次。

+0

- (void)viewWillAppear:(BOOL)animated 每個視圖都會繼承它。 – JoePasq

+0

你指的是什麼代碼? –

+0

與放置在viewDidLoad方法中的視圖圖形和自動調整大小相關的代碼。 – JoePasq