0

我的 tableView 单元格有一个渐变层

CAGradientLayer *gradient = [CAGradientLayer layer];
    gradient.frame = cell.contentView.bounds;
    gradient.colors = 
    [NSArray arrayWithObjects:
     (id)[[UIColor colorWithRed:0.85 green:0.85 blue:0.85 alpha:1] CGColor],
     (id)[[UIColor colorWithRed:0.82 green:0.82 blue:0.82 alpha:1] CGColor], nil];
    [cell.contentView.layer insertSublayer:gradient atIndex:0];

其中,当旋转时明显保持在初始尺寸,直到我打电话

tableview.reloadData

我想知道是否有比这更复杂的方法。

NavigationController 也是如此,它在中心有一个图像,

UIImage *logo = [UIImage imageNamed:@"logo.png"];
UIImageView *logoimageview = 
[[UIImageView alloc] initWithFrame:
 CGRectMake(self.navigationController.navigationBar.bounds.size.width / 2 - logo.size.width / 2, 
            self.navigationController.navigationBar.bounds.size.height / 2 - logo.size.height / 2, 
            logo.size.width, logo.size.height)];

[logoimageview setImage:logo];

[self.navigationController.navigationBar addSubview:logoimageview];

所以图像不会在旋转时重新定位,我不知道导航栏有任何“刷新”方法。

4

1 回答 1

1

I have to warn you that I didn't test this, but I would expect it should work when you set the autoresizingMask. For the table view cell:

cell.contentView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin  | UIViewAutoresizingFlexibleRightMargin;

For the logo image view:

logoimageview.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin  | UIViewAutoresizingFlexibleRightMargin;
于 2012-04-08T18:31:07.630 回答