iOS UITableViewCell内容在第一次滚动时移动

iOS UITableViewCell内容在第一次滚动时移动,第1张

概述您可以在下面的GIF上看到,在第一卷UITableView单元格内容上移动了一点点.你几乎看不到它,边距变得宽1个像素.我以前从未遇到过这个问题.看起来在第一个滚动之前存在一些布局问题,它在事后解决了.在XCode中没有警告,这些自定义单元非常简单,没有布局代码覆盖. 我不知道从哪里开始,我怎么抓住这个小故障? UPDATE.我现在实施了一个明显的解决方法: - (void)scrollTable 您可以在下面的GIF上看到,在第一卷UItableVIEw单元格内容上移动了一点点.你几乎看不到它,边距变得宽1个像素.我以前从未遇到过这个问题.看起来在第一个滚动之前存在一些布局问题,它在事后解决了.在XCode中没有警告,这些自定义单元非常简单,没有布局代码覆盖.

我不知道从哪里开始,我怎么抓住这个小故障?

UPDATE.我现在实施了一个明显的解决方法:

- (voID)scrolltableToFixGlitch {   [self.tableVIEw setContentOffset:CGPointMake(0,1)];   [self.tableVIEw setContentOffset:CGPointMake(0,-1)];}- (voID)vIEwDIDLoad {   [super vIEwDIDLoad];   [self scrolltableToFixGlitch];}

还在调查这个问题.我已经尝试过通用的UItableVIEwCells,没有任何改变.看起来这是VIEw Controller的根视图或tablevIEw布局的问题,而不是表格单元格.

更新2.

我排除了所有动画的问题,问题出在某个不同的地区.这个故障很容易在一个简化的项目上重新创建.我的标签栏控制器基于MHCustomTabBarController,具有自定义segue和一些其他附加功能.这是你重建故障的方法.设置一个项目,其中您的初始VC嵌入在Navigation Controller中.下一个控制器MHCustomTabbarController或子类被推送到导航堆栈.选项卡栏中的第一个可见VC是通用表视图控制器.而已.只有在导航堆栈中按下标签栏控制器时才会出现毛刺.

这里有一些我认为很重要的代码来自标签栏控制器:

-(voID) vIEwWillAppear:(BOol)animated {    [super vIEwWillAppear:animated];   if (self.childVIEwControllers.count < 1) {    [self performSegueWithIDentifIEr:@"vIEwController1" sender:[self.buttons objectAtIndex:0]];  }}-(voID)prepareForSegue:(UIStoryboardSegue *)segue sender:(ID)sender {    if (![segue isKindOfClass:[MHTabbarSegue class]]) {        [super prepareForSegue:segue sender:sender];        return;    }    self.oldVIEwController = self.destinationVIEwController;    //if vIEw controller isn't already contained in the vIEwControllers-Dictionary    if (![self.vIEwControllersByIDentifIEr objectForKey:segue.IDentifIEr]) {        [self.vIEwControllersByIDentifIEr setobject:segue.destinationVIEwController forKey:segue.IDentifIEr];    }    [self.buttons setValue:@NO forKeyPath:@"selected"];    [sender setSelected:YES];    self.selectedindex = [self.buttons indexOfObject:sender];    self.destinationIDentifIEr = segue.IDentifIEr;    self.destinationVIEwController = [self.vIEwControllersByIDentifIEr objectForKey:self.destinationIDentifIEr];    [[NSNotificationCenter defaultCenter] postNotificationname:MHCustomTabbarControllerVIEwControllerChangednotification object:nil]; }

和自定义segue代码:

@implementation MHTabbarSegue- (voID) perform {    MHCustomTabbarController *tabbarVIEwController = (MHCustomTabbarController *)self.sourceVIEwController;    UIVIEwController *destinationVIEwController = (UIVIEwController *) tabbarVIEwController.destinationVIEwController;    //remove old vIEwController    if (tabbarVIEwController.oldVIEwController) {        [tabbarVIEwController.oldVIEwController willMovetoParentVIEwController:nil];        [tabbarVIEwController.oldVIEwController.vIEw removeFromSupervIEw];        [tabbarVIEwController.oldVIEwController removeFromParentVIEwController];    }    destinationVIEwController.vIEw.frame = tabbarVIEwController.container.bounds;    [tabbarVIEwController addChildVIEwController:destinationVIEwController];    [tabbarVIEwController.container addSubvIEw:destinationVIEwController.vIEw];    [destinationVIEwController dIDMovetoParentVIEwController:tabbarVIEwController];}@end

更新3

在我的研究过程中,我发现 – 当子控制器出现时,第一次不调用vIEwWillAppear.但它随后被称为.

解决方法 也许scrollvIEws的contentSize比你的scrollVIEw的框架宽(在这种情况下特别是宽度),导致两个方向的滚动.
您可以尝试将contentSize宽度减小到scrollVIEw的宽度和

self.scrollVIEw.alwaysBounceHorizontal = NO;

如果这不起作用,解决方案是在UIScrollVIEw委托的帮助下以编程方式禁用水平滚动

self.scrollVIEw.delegate = self;[self.scrollVIEw setShowsHorizontalScrollindicator:NO];//for the below UIScrollVIEw delegate function to work do the necessary step in the bottom of my answer.-(voID)scrollVIEwDIDScroll:(UIScrollVIEw *)scrollVIEw{    if (scrollVIEw.contentOffset.x > 0)    scrollVIEw.contentOffset = CGPointMake(0,scrollVIEw.contentOffset.y);}

在.h文件中,您应该通过添加uiscrollviewdelegate将接口行更改为下面的行

@interface VIEwController : UIVIEwController <uiscrollviewdelegate>

你很可能非常了解这个代表部分,但对于其他人可能需要它:D

总结

以上是内存溢出为你收集整理的iOS UITableViewCell内容在第一次滚动时移动全部内容,希望文章能够帮你解决iOS UITableViewCell内容在第一次滚动时移动所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1027016.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-23
下一篇2022-05-23

发表评论

登录后才能评论

评论列表(0条)

    保存