开发者

Rotate UITableViewCell inside a rotated UITableView

Rather than implementing a clunky, potentially bug-ridden custom table, I went with the much simpler rotate table option. The problem comes in when I decide that, rather than initializing rotated contents, I want to rotate the cell itself and cut down on the amount of code in complex cells.

The following lines are immediately after cell configu开发者_开发知识库ration.

This causes every cell to rotate 90° on load, regardless of orientation:

cell.transform =
      (CGAffineTransform)CGAffineTransformRotate(cell.transform, (M_PI / 2.0));

cellRotated = YES;

And this option only rotates the first cell once, but preserves the rotation:

if (!cellRotated) {
    cell.transform =
      (CGAffineTransform)CGAffineTransformRotate(cell.transform, (M_PI / 2.0));

    cellRotated = YES;
}

Can cell orientation be tracked with an existing function (or set thereof)?

I can't find anything about this with Google. There are related questions, but mostly about tables and Portrait/Landscape UI orientations, so the counter-rotation implementation is quite a bit different.


EDIT

If I move cellRotated = YES to viewDidAppear: every cell except one gets rotated. (And then cell reuse makes it so that, in this case, every sixth cell is left alone.)

1-5 is good, 6 is bad, 7-11 is good, 12 is bad, etc (and then it changes in a perfectly logical but entirely unwanted pattern when I hit the end of the table)

Halfway there or a step back, I don't know, but that's what I have now.


If rotation is the only transform you do then why don't you just do this,

cell.transform = CGAffineTransformMakeRotation(M_PI/2.0);

and then,

if ( !CGAffineTransformIsIdentity (cell.transform) ) {
    // Rotated.
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜