HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了iOS UITableViewCell内容在第一次滚动时移动大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
您可以在下面的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内容在第一次滚动时移动所遇到的程序开发问题。

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

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。