我在导航 Controller 的 Root View Controller 中有一个 TableView 。 我使用 JBParallaxCell 作为主视图并转入明细 View ,然后将表单明细 View 返回到 JBParallaxCell,它将重置 imageView 位置。
JBParallaxCell用于在tableview中创建视差 ImageView 。然而,当导航 Controller 推回桌面 View 时,图像会闪烁,因为它重置了 ImageView 的位置。
我该如何修复这个错误? 感谢您的帮助!
以下是一些代码片段:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
// Get visible cells on table view.
NSArray *visibleCells = [self.tableView visibleCells];
for (JBParallaxCell *cell in visibleCells)
{
[cell cellOnTableView:self.tableView didScrollOnView:self.view];
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
JBViewController *controller = [[JBViewController alloc] init];
[self.navigationController pushViewController:controller animated:YES];
}
JBParallaxCell.h:
@interface JBParallaxCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UIImageView *parallaxImage;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *subtitleLabel;
- (void)cellOnTableView:(UITableView *)tableView didScrollOnView:(UIView *)view;
@end
JBParallaxCell.m:
@implementation JBParallaxCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (void)cellOnTableView:(UITableView *)tableView didScrollOnView:(UIView *)view
{
NSLog(@"cell scrolling...");
CGRect rectInSuperview = [tableView convertRect:self.frame toView:view];
float distanceFromCenter = CGRectGetHeight(view.frame)/2 - CGRectGetMinY(rectInSuperview);
float difference = CGRectGetHeight(self.parallaxImage.frame) - CGRectGetHeight(self.frame);
float move = (distanceFromCenter / CGRectGetHeight(view.frame)) * difference;
CGRect imageRect = self.parallaxImage.frame;
imageRect.origin.y = -(difference/2)+move;
self.parallaxImage.frame = imageRect;
}
最佳答案
我也有类似的问题,在我从 View Controller 调用 popViewControllerAnimated:YES
后,我的表格 View 自动滚动到顶部位置。
而且我认为这是IOS7/8的一个bug。 在IOS9+中是可以的。
estimatedRowHeight
与实际高度相差越大,当推送转场发生时,表格跳动的幅度就越大。
在评论此行之后:
self.tableView.estimatedRowHeight = 64.0;
UITableView
不再跳转了。
关于ios - 导航 Controller 推送另一个 Controller 触发tableview调用scrollViewDidScroll :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25247055/