1

所以我有一个应用程序,我正在尝试针对所有方向进行优化。但是我遇到了表格视图和自动旋转的问题。这是纵向时的外观:

肖像

现在,当我旋转设备时,它看起来像这样:

景观不好

但是,当我触摸桌子时,它会自行修复,看起来像这样:

景观不错

那么,当视图旋转而不等待用户点击表格时,我怎样才能让它自动发生呢?谢谢!

我尝试使用以下代码没有成功:

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation) fromInterfaceOrientation {    
    [self.tableView reloadData];
}
4

3 回答 3

1

所以问题不在于桌子,而在于我使用的遮罩层。看起来 CALayers 不支持自动调整大小,所以我使用以下代码:

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation) fromInterfaceOrientation {    
    maskLayer.frame = self.maskView.bounds;
}

它在旋转时没有动画。它完成旋转,然后为蒙版设置动画。这很奇怪,但它对我有用。如果有人有更好的解决方案,我会删除我的答案并将其提供给其他人。

于 2013-05-17T01:18:02.653 回答
0
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
     return YES;

    //return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

return yes 是 autorotaion 需要的。

于 2013-05-18T06:42:05.680 回答
0

我不知道这是否与您的外观完全相同(我无法从您的照片中真正看出)。表格底部的单元格逐渐变为黑色。此代码位于 UIViewController 中,并添加了一个表视图作为子视图。表格视图被赋予了蓝色背景色。这在旋转时非常有效。

-(void)viewWillLayoutSubviews {
    self.maskGradient.frame = self.view.bounds;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.maskGradient = [CAGradientLayer layer];
    self.maskGradient.frame = self.view.bounds;
    self.maskGradient.colors = @[(id)[[UIColor colorWithRed:0 green:0 blue:0 alpha:1] CGColor],(id)[[UIColor colorWithRed:0 green:0 blue:0 alpha:1] CGColor],(id)[[UIColor colorWithRed:0 green:0 blue:0 alpha:.2] CGColor]];
    self.maskGradient.locations = @[@0.0f,@0.9f,@1.00f];
    self.view.layer.mask = self.maskGradient;

    // other code to populate the table
    [self.tableView reloadData];
}

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    cell.backgroundColor = [UIColor clearColor];
}
于 2013-05-17T02:11:11.653 回答