1

我想知道从以下布局中实现的最佳方法/正确方法?我想将 UIImageView 放在 UITableViewCell 之外的带有静态单元格的 UITableView 中。

我要实现的目标的屏幕截图

我通过使用以下代码为第 1 节中的单元格子类化 UITableViewCell 完成了以下操作

- (void)setFrame:(CGRect)frame {
    frame.size.width -= 125.0;
    [super setFrame:frame];
}

在 UITableViewController 的 viewDidLoad 中,我添加 UIImageView 并根据自定义 UITableViewCell 的宽度定位它。

这种工作,但我不知道如何处理轮换以及我到目前为止所做的是否是正确的方法?

4

2 回答 2

0

有不同的方法可以做到这一点。一种是设置表格视图的宽度,如图 2 所示,使用自定义表格视图单元格并在所需的单元格上添加图像,以便显示单元格数据和图像。我认为自定义单元格将是更好的解决方案。告诉我您是否在问我回答的问题,如果不是,那么我会查看我的答案,谢谢。

于 2012-05-02T19:02:14.610 回答
0

我设法使用以下方法产生了我想要的东西,这不是最好的方法或最干净的方法,但是由于 StackOverFlow 没有人给出更好的建议,我认为我最好回答这个问题。

我对前 3 个 UITableViewCells 进行了子类化,并设置了一个框架大小以考虑我的图像大小。

- (void)setFrame:(CGRect)frame {
float cellWidth = (frame.size.width - 345);
frame.size.width = cellWidth;

[super setFrame:frame];

}

然后在我的 UITableViewController 的 viewDidLoad 中,我使用 tableview 中的第一个静态单元格作为 IBOutlet(“firstCell”)创建和定位 UIImageView。然后我设置了 autoResizingMask 来排序旋转,最后将 UIImageView 添加到视图中。

//Create and position the image view
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake((firstCell.frame.size.width), (firstCell.frame.origin.y + 70), 300, 137)];

// Add border and round corners of image view to make style look a little like tableviewcells
[imageView.layer setBorderColor:[UIColor colorWithWhite:0 alpha:0.5].CGColor];
[imageView.layer setBorderWidth:2.0];
[imageView.layer setCornerRadius:5.0];
[imageView setClipsToBounds:YES];

//Set the image in the image view
UIImage *image = [UIImage imageNamed:@"defaultPicture.png"];
imageView.image = image;

//Set resizing of image view for when view is rotated
imageView.contentMode = UIViewContentModeRedraw;
imageView.autoresizingMask = UIViewContentModeScaleAspectFit;

//Add tap gesture for imageview to initiate taking picture.
imageView.userInteractionEnabled = YES;
UITapGestureRecognizer *imageViewTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(takePicture:)];
[imageView addGestureRecognizer:imageViewTap];

//Add image view to view
[self.view addSubview:imageView];

景观 肖像

这还没有经过全面测试,我敢肯定这不是一个很好的实现,但它是我所追求的效果的起点。如果您知道更好的方法,请回复。

注意:上面的代码是为我在 iPad 上的应用程序编写的,但截图来自我在 iPhone 上所做的测试

于 2012-05-04T08:50:35.503 回答