iphone - 什么时候需要在转换 iOS 后重置 view.frame 属性

标签 iphone ios uitableview pulse

我正在制作一个像 Pulse 新闻阅读器一样的水平表格 View 。我在网上找到了几个示例并使其正常工作,但我想知道何时需要在转换后设置 view.frame 属性。

我发现的示例在 90 度旋转后重置垂直 TableView 单元格内的水平 TableView 框架

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;

}

但不要在单元格变换(旋转)后重置水平表格单元格的框架:
- (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;

}

我尝试重置单元格的框架,但它对输出没有影响,即使我提供了
cell.frame = CGMakeRect(200, 200, cell.frame.size.height, cell.frame.size.width)

哪个应该在表格 View 周围移动单元格,不是吗?

如果我不重置 self.tableViewCell.horizontalTableView.frame 的框架水平表旋转,但位置错误。

为什么我需要在旋转后重置水平表格 View 的框架,而不是单个单元格(也旋转)?

谢谢!

//iPortable 插图
enter image description here

最佳答案

啊,好的,再读一遍我明白你在问什么^^

  • 设置框架会导致重绘 View 。这需要完成,否则旧图形可能会干扰并且看起来很难看。重绘也应该锐化绘制线。
  • 您将单元格的框架设置在其他位置(此处为 200,200),但它没有任何效果是完全正常的。单元格不能位于 CGPointZero 以外的其他位置.如果你想取代它,你必须创建一个更大的 View 并移动内容。 ( View 可以 是半透明的,但它会显着减慢旧设备上的滚动速度)
  • 你问为什么你不必重绘每个单元格而只需要重绘tableView。实际上我并不确切知道这一点,但实际上应该是表格 View 的框架更改。通常情况下,通过旋转设备会发生帧变化,从而改变宽度。现在,开发人员将每个单元格更新为新大小是非常愚蠢的。感谢 Apple,tableView 为屏幕上可见的每个单元格调用必要的更新请求。最终,所有 View 都调用了相同的方法:drawRect:
  • 关于iphone - 什么时候需要在转换 iOS 后重置 view.frame 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7772016/

    相关文章:

    ios - 自定义 TableViewController 在 Swift 3 中播放声音和崩溃

    ios - 为 UITableViewCell 指定 Segue

    iphone - 如何通过 iPad 中的应用程序调整设备的亮度

    iphone - PlaySystemSound 静音开关打开

    html - ios8 Webview svg 嵌入 html 不显示

    ios - 在代码中更改 iOS 应用名称

    ios - 如何从扩展/嵌套的 UITableViewCell 导航到 View Controller

    iphone - iOS 中的内存保留和泄漏

    使用 SPARQL 使用 Wiki 中的数据进行 iPhone 开发

    iphone - 给循环效果赋予 ScrollView