简体   繁体   English

iOS开发Animating Table视图自定义单元格内容

[英]iOS development Animating Table view custom cell content

I am working on new application and i would like to have custom table view. 我正在开发新的应用程序,我想拥有自定义表格视图。 I need to have cell that have 2 labels 1 check box and 2 buttons. 我需要具有2个标签1复选框和2个按钮的单元格。 The problem i have is that 2 buttons need to be shown only if user press edit button on top. 我的问题是仅当用户按下顶部的编辑按钮时才需要显示2个按钮。 I made all this to work but i have some problem with reusable cells or something like that. 我使所有这些都能正常工作,但是我对可重复使用的单元格或类似的东西有一些问题。

I made custom cell class so i can assign data to it. 我做了自定义单元格类,以便我可以为其分配数据。

First state is: First state on img 第一个状态是:img上的第一个状态

Then when user press edit button on top i need everyting to animate and come to right place. 然后,当用户按下顶部的编辑按钮时,我需要安装动画并到达正确的位置。 I want text to animate to right to make space for button, delete button needs to come animated from left side and edit butom to come in animated from right side. 我希望文本向右移动以为按钮留出空间,删除按钮需要从左侧进行动画处理,而编辑按钮需要从右侧进行动画处理。

This is what i want to get after animations are done: Second state on img 这是动画完成后我想要得到的:img上的第二种状态

I made all this to work but now i have problem that first 2 cells that will come on screen after i scroll down are not effected by my code :( 我使所有这些都能正常工作,但是现在我有一个问题,即我向下滚动后将出现在屏幕上的前两个单元格不受我的代码的影响:(

This is what i get: Third state on img 这就是我得到的:img上的第三种状态

i will post my project code here and if some1 can help me with it i would be more then thrilled. 我将在这里发布我的项目代码,如果some1可以帮助我,我会更兴奋。 I point me to right way to do this. 我指出正确的方法。

Code downoald: https://www.mediafire.com/?g1g6d7h33mpkyt7 代码下载: https ://www.mediafire.com/ g1g6d7h33mpkyt7

and i will post some code here that i think is crucial to my problem: 我将在此处发布一些我认为对我的问题至关重要的代码:

for animations i use: 对于动画我使用:

[cell.infoView setFrame:CGRectMake(20, CGRectGetMinY(cell.infoView.frame), CGRectGetWidth(cell.infoView.frame), CGRectGetHeight(cell.infoView.frame))];
        [UIView animateWithDuration:0.4
                              delay:0
                            options:UIViewAnimationOptionCurveEaseIn
                         animations:^{
                             [cell.infoView setFrame:CGRectMake(70, CGRectGetMinY(cell.infoView.frame), CGRectGetWidth(cell.infoView.frame), CGRectGetHeight(cell.infoView.frame))];
                         }
                         completion:nil];

for cell init i use: 对于单元格初始化,我使用:

CICustomCell *cell;
cell = [tableView dequeueReusableCellWithIdentifier:CellTableIdentifier];
if(cell == nil)
{
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"HCICustomCell" owner:nil options:nil];
    cell = [nib objectAtIndex:0];
}

cell.itemName = [dwarves objectAtIndex:indexPath.row];

cell.quantity = 25.99;

for table init i use: 对于表初始化,我使用:

UITableView *tableView = (id)[self.view viewWithTag:1];

tableView.rowHeight = 60;

UINib *nib = [UINib nibWithNibName:@"HCICustomCell"
                            bundle:nil];


[tableView registerNib:nib forCellReuseIdentifier:CellTableIdentifier];

img: http://i270.photobucket.com/albums/jj109/lazardj/scsimg.jpg~original img: http : //i270.photobucket.com/albums/jj109/lazardj/scsimg.jpg~原始

EDIT: 编辑:

I also tried something now. 我现在也尝试了一些。 If i start my activity then scroll down a bit so i get some new cells i dont have this problem. 如果我开始活动,请向下滚动一点,以便获得一些新单元格,但我没有这个问题。 So it must be something with creating cells or reusability of cells or something like that. 因此,必须具有创建单元或单元可重用性之类的功能。 I am new to ios development so i cant figure this out on my own :( so please help :) Thanks 我是ios开发的新手,所以我无法自己解决这个问题:(所以请帮忙:)谢谢

In your cellForRow function in your tableview delegate you need to deal with the location of your labels. 在tableview委托的cellForRow函数中,您需要处理标签的位置。 So every time you request a new (or reused) cell you need to check whether you are in edit mode and then set the labels frames accordingly. 因此,每次您请求一个新的(或重用的)单元格时,都需要检查您是否处于编辑模式,然后相应地设置标签框架。

It appears as you are already doing this for the buttons, as they show up in the proper place, but the labels are being re-used at their initial locations (when they were released by the tableview). 出现在按钮上的位置已经显示出来,因为它们已经显示在正确的位置,但是标签在其初始位置(当Tableview释放它们时)已被重新使用。

I've had a look at your project, and the problem appears to stem from using AutoLayout. 我看过您的项目,问题似乎源于使用AutoLayout。 The automatic constraints appear to be interfering with your view layouts. 自动约束似乎正在干扰您的视图布局。 If you go to your HCICustomCell.xib file and click on the file inspector tab, you'll see a checkbox for " Use Autolayout ". 如果转到HCICustomCell.xib文件并单击文件检查器选项卡,则会看到“ 使用自动版式 ”复选框。 Uncheck this and then set the auto-resizing constraints manually for each view in the Size Inspector tab. 取消选中此选项,然后在“大小检查器”选项卡中为每个视图手动设置自动调整大小约束。 I've uploaded a revised version of your project here . 我已经上传了项目的修订版本在这里

SOLUTION: 解:

I done some more work on this. 我对此做了更多工作。 Tried solutions you provided me but there are still times when it gets bugged so i came with my own one. 您提供给我的尝试过的解决方案,但是仍然有很多时候遇到问题,所以我附带了自己的解决方案。 I figured out that the problem is that you cant move view in cell on first init but you can show hide them. 我发现问题是您不能在初次启动时在单元格中移动视图,但是可以显示隐藏它们。 So i decided to try to make same info view on place where it needs to be when enable is on. 因此,我决定尝试在启用启用功能的地方创建相同的信息视图。 When enable is off its hidden and when enable is on it shows up. 当启用关闭时,其隐藏,启用时显示。 This is what fixed my problem :) I know its not the smartest way to do things but i managed to do what i wanted and its not messing performances of application. 这就是解决我的问题的方法:)我知道这不是最聪明的处理方式,但是我设法做到了自己想要的事,并且不会破坏应用程序的性能。

This is project with fixed bugs. 这是带有固定错误的项目。 If any1 want can use it :) 如果有的话可以使用它:)

Thanks for all your time and suggestions. 感谢您的所有时间和建议。

Project: https://www.mediafire.com/?uhatbh8c20xu49v 项目: https//www.mediafire.com/?uhatbh8c20xu49v

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM