我正在使用带有 3 个按钮的自定义 tableviewcell。
我在自定义单元格中的 layoutSubviews 方法中设置了按钮的框架:
-(void)layoutSubviews
{
[super layoutSubviews];
CGRect frame;
if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
{
frame = CGRectMake(310, 7, 55, 35);
_prod.frame = frame;
frame = CGRectMake(365, 7, 55, 35);
_leva.frame = frame;
frame = CGRectMake(220, 4, 65, 65);
_imageButton.frame = frame;
}
else{
frame = CGRectMake(150, 7, 55, 35);
_prod.frame = frame;
frame = CGRectMake(205, 7, 55, 35);
_leva.frame = frame;
frame = CGRectMake(120, 4, 65, 65);
_imageButton.frame = frame;
}
}
问题是,当用户滚动表格 View 时,在更改方向后,例如,所有按钮都回到原来的纵向位置。 下面是我如何初始化单元格:
LojaCell *cell = (LojaCell *) [tableView dequeueReusableCellWithIdentifier: @"LojaCell"];
if(cell == nil) cell = [[LojaCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"LojaCell"];
最佳答案
您可能必须将相同的方向敏感代码添加到 cellForRowAtIndexPath:,以便在 tableview 重新加载或重新创建单元格时它们加载到正确的位置。因为您正在使用 dequeueReusableCells,它会删除屏幕外的单元格以提高性能,这可能会解释滚动时的行为。
关于ios - 在 InterfaceOrientation 上的 customCell 内重新定位 UIButtons,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15663370/