我正在使用带有 tableview 的自定义 sectionheader 类,并在旋转后出现一些意外行为。这是用例:
- 点击 UITableView 中的单元格
- 视图推入堆栈。
- 将视图旋转为横向。
- 旋转回纵向。
- 弹出视图。
- 仅在 iPhone 3G 上,横向尺寸的部分标题现在出现在视图中间的某个位置(除了纵向尺寸的部分标题,它应该出现在 tableview 的顶部)。无关的标题随着 UITableView 单元格滚动,并且在视图之间切换(UITableView 嵌套在 UITabBarController 中)并不能解决问题。
我无法在 iPhone 4 或模拟器中重现此问题。似乎出于某种原因,在弹出第二级视图后,一个面向横向的 sectionheaderview 被添加到 uitableview 中,但为什么会这样呢?请注意,使用默认(而不是自定义)标头时会重现相同的问题。我还检查了是否是设备方向返回不正确的问题,但似乎并非如此。
如果有帮助,这是自定义 SectionHeaderView 类的初始化代码:
-(id)initWithFrame:(CGRect)frame title:(NSString*)title delegate:(id <SectionHeaderViewDelegate>)aDelegate {
self = [super initWithFrame:frame];
if (self != nil) {
float lineHeight = 0.5f;
// check line sizing for retina/non-retina
if (![Utilities hasRetina])
{
lineHeight = 1.0f;
}
// Set up the tap gesture recognizer.
delegate = aDelegate;
// Create and configure the title label.
CGRect titleLabelFrame = self.bounds;
titleLabelFrame.origin.y -= 12.5;
titleLabel = [[UILabel alloc] initWithFrame:titleLabelFrame];
titleLabel.text = title;
titleLabel.textAlignment = UITextAlignmentCenter;
titleLabel.font = [UIFont fontWithName:@"Georgia" size:15.0];
titleLabel.textColor = [UIColor whiteColor];
titleLabel.backgroundColor = [UIColor clearColor];
[self addSubview:titleLabel];
// add thin white line to top of section header
UIView *topBorder = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.bounds.size.width, lineHeight)];
[topBorder setBackgroundColor:[UIColor whiteColor]];
[self addSubview:topBorder];
[topBorder release];
// Set the colors for the gradient layer.
static NSMutableArray *colors = nil;
if (colors == nil) {
colors = [[NSMutableArray alloc] initWithCapacity:3];
UIColor *color = nil;
color = [UIColor colorWithRed:57.0/255.0 green:56.0/255.0 blue:105.0/255.0 alpha:1.0];
[colors addObject:(id)[color CGColor]];
color = [UIColor colorWithRed:54.0/255.0 green:53.0/255.0 blue:95.0/255.0 alpha:1.0];
[colors addObject:(id)[color CGColor]];
color = [UIColor colorWithRed:57.0/255.0 green:56.0/255.0 blue:105.0/255.0 alpha:1.0];
[colors addObject:(id)[color CGColor]];
}
[(CAGradientLayer *)self.layer setColors:colors];
[(CAGradientLayer *)self.layer setLocations:[NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0], [NSNumber numberWithFloat:0.48], [NSNumber numberWithFloat:1.0], nil]];
}
return self;
}
为什么要在纵向视图中添加自定义 SectionHeaderView 的额外横向版本,仅在 iPhone 3G 上?
提前感谢您的帮助。