框架在cellForRowAtIndexPath中没有变化 [英] Frame is not changing in cellForRowAtIndexPath
问题描述
对于某些条件,我想在 cellForRowAtIndexPath
中的单元格内更改 view
的x位置框架。我使用了以下代码。但它不会改变视图的 x位置
框架。
I want to change the x position frame of view
inside the cell in cellForRowAtIndexPath
for certain conditions. I have used the following code. But it does not change the view's x position
frame.
- (void)viewDidLoad {
[super viewDidLoad];
UINib *nib = [UINib nibWithNibName:@"GoalDetailsCustomCardCell" bundle:nil];
[goalDetailsTableView registerNib:nib forCellReuseIdentifier:@"CardCell"];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
GoalDetailsTableViewCell *cell = [goalDetailsTableView dequeueReusableCellWithIdentifier:@"CardCell"];
if(cell == nil)
{
cell = [goalDetailsTableView dequeueReusableCellWithIdentifier:@"CardCell"];
}
NSLog(@"%f", cell.cardDetails.frame.origin.x);
[UIView animateWithDuration: 0.5 animations:^{
cell.cardDetails.frame = CGRectOffset(cell.cardDetails.frame, -322.0, 0.0);
// CGRectOffset(cell.cardView.frame, -320.0, 0.0);
cell.actionCardReminder.frame = CGRectOffset(cell.actionCardReminder.frame, -322.0, 0.0);
}];
NSLog(@"%f", cell.cardDetails.frame.origin.x);
return cell;
}
单元格中的视图按预期移动但不是负面移动。它仍然显示cardDetails视图而不是actionCardReminder视图。
The view in cell moving as expected but not to the negative side. Its still showing the cardDetails view not the actionCardReminder view.
注意:NSLog将视图框显示为更改x位置但视图未移动到-322.0位置。 / p>
Note: The NSLog show the view frame as change x position but the view is not moving to -322.0 position.
推荐答案
由于iOS布局渲染过程,您的自定义UITableViewCell的layoutSubviews可能会多次调用。在您的情况下,您可以更改GoalDetailsTableViewCell类的layoutSubviews方法中的项目框架。
Because of the iOS layout render process, your custom UITableViewCell's layoutSubviews may called more than once. In your case you can change the items frames in the GoalDetailsTableViewCell class's layoutSubviews method.
@implementation GoalDetailsTableViewCell
-(void)layoutSubviews
{
[super layoutSubviews];
[UIView animateWithDuration: 0.5 animations:^{
cell.cardDetails.frame = CGRectOffset(cell.cardDetails.frame, -322.0, 0.0);
// CGRectOffset(cell.cardView.frame, -320.0, 0.0);
cell.actionCardReminder.frame = CGRectOffset(cell.actionCardReminder.frame, -322.0, 0.0);
}];
NSLog(@"%f", cell.cardDetails.frame.origin.x);
}
@end
这篇关于框架在cellForRowAtIndexPath中没有变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!