转换iOS之后何时需要重置view.frame属性 [英] When Do You Need To Reset the view.frame Property After a Transformation iOS

查看:129
本文介绍了转换iOS之后何时需要重置view.frame属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在像Pulse News阅读器一样制作水平表格视图.我在网上找到了几个示例,并且可以运行,但是想知道何时需要在转换后设置view.frame属性.

I'm making a horizontal table view like the Pulse news reader. I've found several examples online and have it working, but am wondering when we need to set the view.frame property after a transformation.

我发现的示例在旋转90度后在垂直表格视图单元格中重置了水平表格视图的框架

The examples I've found reset the frame of the horizontal table view within the vertical table view cell after the 90 degree rotation

self.tableViewCell.horizontalTableView.transform = rotateTable;
self.tableViewCell.horizontalTableView.frame = CGRectMake(0, 0, self.tableViewCell.horizontalTableView.frame.size.width, self.tableViewCell.horizontalTableView.frame.size.height);

更多上下文:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
TableViewCell *cell = (TableViewCell*)[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    [[NSBundle mainBundle] loadNibNamed:@"TableViewCell" owner:self options:nil];

    CGAffineTransform rotateTable = CGAffineTransformMakeRotation(-M_PI_2);
    self.tableViewCell.horizontalTableView.transform = rotateTable;
    self.tableViewCell.horizontalTableView.frame = CGRectMake(0, 0, self.tableViewCell.horizontalTableView.frame.size.width, self.tableViewCell.horizontalTableView.frame.size.height);

    self.tableViewCell.contentArray = [self.arrays objectAtIndex:indexPath.section];

    self.tableViewCell.horizontalTableView.allowsSelection = YES;
    cell = self.tableViewCell;
    self.tableViewCell = nil;

}

cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;

}

但是在单元格转换(旋转)后,请勿重置水平表格单元格的框架:

But don't reset the frame of the horizontal table cell after the cell's transformation (rotation):

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [self.horizontalTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {

    [[NSBundle mainBundle] loadNibNamed:@"GameTableViewCell" owner:self options:nil];
    cell = self.gameTableCell;
    self.gameTableCell = nil;
}

CGAffineTransform rotateImage = CGAffineTransformMakeRotation(M_PI_2);
cell.transform = rotateImage;
return cell;

}

我尝试重置单元格的框架,即使我提供了它也不会影响输出

I tried resetting the cell's frame and it had no effect on the output, even if I supplied

cell.frame = CGMakeRect(200, 200, cell.frame.size.height, cell.frame.size.width)

哪个应该在表格视图"中移动单元格,不是吗?

Which should have moved the cell around the Table View, no?

如果我不重置self.tableViewCell.horizontalTableView.frame的帧,则会旋转水平工作台,但是位置错误.

If I don't reset the frame of self.tableViewCell.horizontalTableView.frame the horizontal table is rotated, but in the wrong location.

为什么旋转后需要重置水平表格视图"的框架,而不重置单个单元格(也旋转了)?

Why is it that I need to reset the frame of the horizontal Table View after rotating it, but not the individual cells (which are also rotated)?

谢谢!

//iPortable的插图

// illustration by iPortable

推荐答案

嗯,再读一次就可以了,我知道你在问什么^^

ahh ok after reading it again I understand what you're asking ^^

  1. 设置框架会导致重画视图.需要这样做,因为否则旧的图形可能会干扰并且看起来很丑.重新绘制也应使绘制线条更清晰.
  2. 您将单元格的框架设置为其他位置(此处为200,200),但是完全无效是完全正常的.单元格不能在CGPointZero之外.如果要替换它,则必须创建一个更大的视图并移动内容. (视图可以是半透明的,但会大大降低旧设备上的滚动速度)
  3. 您问为什么不必重新绘制每个单元格,而只需重新绘制tableView.其实我并不十分了解,但实际上应该是表格视图的框架更改.通常,通过旋转设备使框架发生变化,从而改变宽度.现在,对于开发人员而言,将每个单元更新为新的大小将是非常愚蠢的.多亏了Apple,tableView才为屏幕上可见的每个单元格调用必要的更新请求.最终,所有视图都调用相同的方法:drawRect:
  1. Setting the frame results in redrawing the view. This needs to be done because otherwise the old graphics may interfere and it looks ugly. The redraw should sharpen the draw lines too.
  2. you set your cell's frame to be positioned somewhere else (here 200,200) but it is completely normal that it has no effect. A cell cannot be elsewhere than CGPointZero. If you like to displace it, you have to create a bigger view and move the content. (the view can be translucent but it will slow down the scrolling on older devices dramatically)
  3. you ask why you don't have to redraw each cells but only the tableView. Actually I don't know this exactly but it should be in fact of the frame change of the table view. Normally a frame change occur by rotating the device so that the width changes. Now it would be pretty stupid for a developer to update each cell for the new size. Thanks to Apple the tableView calls the necessary update request for each cell which is visible on screen. Eventually the same methods are called for all views: drawRect:

这篇关于转换iOS之后何时需要重置view.frame属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆