iphone:旋转可视视图时旋转翻转视图

iphone:旋转可视视图时旋转翻转视图,iphone,Iphone,旋转具有两个视图的视图控制器时,会出现调整大小的问题,我使用翻转动画在这两个视图之间切换。 如果执行以下步骤,则会出现问题: 查看tableview时旋转设备 单击“信息”按钮 旋转设备(infoView显示为拉伸) 单击信息按钮(tableview显示为拉伸) 似乎未添加到superview的视图未正确调整大小,因为旋转设备时它不是复合视图的一部分。。是否有任何方法可以正确地自动调整此视图的大小 下面是一个代码示例 - (void)viewDidLoad { [super viewDi

旋转具有两个视图的视图控制器时,会出现调整大小的问题,我使用翻转动画在这两个视图之间切换。 如果执行以下步骤,则会出现问题:

  • 查看tableview时旋转设备
  • 单击“信息”按钮
  • 旋转设备(infoView显示为拉伸)
  • 单击信息按钮(tableview显示为拉伸)
  • 似乎未添加到superview的视图未正确调整大小,因为旋转设备时它不是复合视图的一部分。。是否有任何方法可以正确地自动调整此视图的大小

    下面是一个代码示例

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

    谢谢

    尝试将代码放入视图将显示:动画。每次视图出现时都会调用它。视图加载只调用一次。

    -(void)视图将出现:(BOOL)已设置动画的每个视图都将继承该视图。与视图绘图和自动调整大小相关的代码将放入viewDidLoad方法中。