1

UITableView在我的 XIB 中。现在我有两个方向问题。

1)我将UIImageView,UILabel作为子视图添加到cell.contentview. 因为我需要每个表格单元格中的图像和标签。为此,我在CellforRowAtIndexPath. 但是当我尝试将视图旋转到横向时,我将这些图像和标签放在我提到的相同位置,即使我用WillRotateOrientation. 为什么会发生这种情况?以及如何解决这个问题?这是我的代码,

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{

    imgView1 = [[UIImageView alloc] initWithFrame:CGRectMake(680, 60, 40, 40)];
    [imgView1 setImage:[UIImage imageNamed:@"Downloaded.png"]];

     if([[[appDelegate selectDB] valueForKey:@"bookname"] containsObject:[listOfBooks objectAtIndex:indexPath.row]] )
      {
         [cell.contentView addSubview:imgView1];
      }
}

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{

     [self handleInterfaceRotationForOrientation:toInterfaceOrientation];

if (toInterfaceOrientation==UIInterfaceOrientationLandscapeRight) 
{
   imgView1.frame = CGRectMake(890,0, 40, 40);
}
else if (toInterfaceOrientation==UIInterfaceOrientationLandscapeLeft) 
{
   imgView1.frame = CGRectMake(890,0, 40, 40);
}
else if (toInterfaceOrientation==UIInterfaceOrientationPortrait)
{
   imgView1.frame = CGRectMake(690, 60, 40, 40);
}
else 
{
   imgView1.frame = CGRectMake(690, 60, 40, 40);
}

// 这里我只是单独添加了图像视图代码。

2)我有一个带有一个进度视图和取消按钮的警报视图。当我尝试将其从纵向旋转到横向/横向到纵向时,我的警报视图被尖叫并且无法查看进度视图并且取消按钮自动增大其大小。

- (void)willPresentAlertView:(UIAlertView *)alertView 
{

     if(alertView.tag == kAlertViewOne)
     {
          progressAlert.frame = CGRectMake(270, 380, 300, 200);

              activityView = [[UIActivityIndicatorView alloc]  initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    activityView.frame = CGRectMake(139.0f-18.0f, 40.0f, 37.0f, 37.0f);
    [progressAlert addSubview:activityView];
    [activityView startAnimating];


      DownloadingcancelButton=[(NSMutableArray*)[progressAlert valueForKey:@"_buttons"] objectAtIndex:0];

      DownloadingcancelButton.frame=CGRectMake(70, 115, 150, 45);

   }
   else if(alertView.tag == kAlertViewTwo)
   {


       UIButton *cancelButton=[(NSMutableArray*)[redownloadAlert valueForKey:@"_buttons"] objectAtIndex:1];

       cancelButton.frame=CGRectMake(150, 85, 80, 45);

       UIButton *YESButton=[(NSMutableArray*)[redownloadAlert valueForKey:@"_buttons"] objectAtIndex:0];

       YESButton.frame=CGRectMake(40, 85, 80, 45);
    }
 }

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{
     [self handleInterfaceRotationForOrientation:toInterfaceOrientation];

    if (toInterfaceOrientation==UIInterfaceOrientationLandscapeRight) 
    {
            progressAlert.frame = CGRectMake(270, 380, 300, 250);
            DownloadingcancelButton.frame=CGRectMake(70, 160, 150, 45);
    }
    else if (toInterfaceOrientation==UIInterfaceOrientationLandscapeLeft) 
    {
           progressAlert.frame = CGRectMake(270, 380, 300, 250);
           DownloadingcancelButton.frame=CGRectMake(70, 160, 150, 45);
    }
    else if (toInterfaceOrientation==UIInterfaceOrientationPortrait)
    {
           progressAlert.frame = CGRectMake(270, 380, 300, 200);
           DownloadingcancelButton.frame=CGRectMake(70, 115, 150, 45);
    }
    else
    {
           progressAlert.frame = CGRectMake(270, 380, 300, 200);
           DownloadingcancelButton.frame=CGRectMake(70, 115, 150, 45);
    }

简单的定位问题,但我在过去的一天来到这里。请帮我解决这个问题。提前致谢。

4

0 回答 0