iOS 8 cell resizing

天大地大妈咪最大 提交于 2019-12-05 21:04:38

i got similar problerm.

solve it by:

- (void)setFrame:(CGRect)frame
{
  NSInteger inset = kDefaultViewPadding;
  frame.origin.x += inset;
  frame.size.width = kMainScreenWidth - 2*inset;

  [super setFrame:frame];
}

where

#define kMainScreenWidth            ([[UIScreen mainScreen] bounds].size.width)

,

don't use code like:

    frame.origin.x += TABLE_PADDING;

or

    frame.size.width = self.superview.frame.size.width - (2.0f * TABLE_PADDING);

otherwise, every time refresh tableview , the cell's width reduce (2.0f * TABLE_PADDING).

HashtagMarkus

I don't know why the behavior changed in iOS 8 but I found a workaround.

In my case I changed the setFrame message to the following:

-(void) setFrame:(CGRect) frame {
    frame.origin.x += TABLE_PADDING;
    frame.size.width = self.superview.frame.size.width - (2.0f * TABLE_PADDING);
    [super setFrame: frame];
}

So I'm using the superview boundings for calculation. However this might not work in any case...

I ran into another problem while reordering the cell.

In case you are reordering try this:

-(void) setFrame:(CGRect) frame {

    if(isDragging)
        frame.origin.x = self.supervire.frame.origin.x + TABLE_PADDING;
    else
        frame.origin.x += TABLE_PADDING;

    frame.size.width = self.superview.frame.size.width - (2.0f * TABLE_PADDING);
    [super setFrame: frame];
}

To get the information if the TableCell is dragging I used the solution provided in this question: How to get notified of UITableViewCell move start and end

Edit I ran into more and more problems with the setFrame message, so I decided NOT to use the standard TableViewController. Now I'm using a standard ViewController with a searchbar and a search display controller. And a table View inside the controllers View. That way I can use autolayout constraints to adjust the table width. This seems to be the best solution for my case since I could not find any way to get it to work (in any case) using the setFrame message.

I have partially solved my problem by moving the code from setFrame to layoutSubviews and instead of using self.frame, I use a property saved in awakeFromNib where I keep my bounds:

- (void)layoutSubviews
{
[super layoutSubviews];
    CGRect bounds = self.cellBounds;
    CGRect boundsWithInsets = CGRectMake(bounds.origin.x + horizontalPadding,
                                        bounds.origin.y + verticalPadding,
                                        bounds.size.width - 2 * horizontalPadding,
                                        bounds.size.height - 2 * verticalPadding);
    [super setBounds:boundsWithInsets];
}

The problem arises again when I swipe to enter in editing mode, and all my cells loose their left padding (as mentioned by @Zerd1984)

I should also mention that I use TLIndexPathTools library which currently is not updated to solve this issue.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!