gpt4 book ai didi

ios - 导航 Controller 推送另一个 Controller 触发 tableview 调用 scrollViewDidScroll :

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:21:36 25 4
gpt4 key购买 nike

我在导航 Controller 的 Root View Controller 中有一个 TableView 。我将 JBParallaxCell 用于主视图并转入 detailView,然后将表单 detailview 返回给 JBParallaxCell,它将重置 imageView 位置。

JBParallaxCell 用于在表格 View 中创建视差 ImageView 。但是,当导航 Controller 推回 tableview 时图像会闪烁,因为它会重置 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 后,我的 TableView 自动滚动到顶部位置。

而且我认为这是IOS7/8的一个bug。在IOS9+下是可以的。

estimatedRowHeight 与实际高度的差异越大,当 push segue 发生时表格跳动的幅度就越大。

评论这一行之后:

self.tableView.estimatedRowHeight = 64.0;

UITableView 没有再跳了。

关于ios - 导航 Controller 推送另一个 Controller 触发 tableview 调用 scrollViewDidScroll :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25247055/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com