我设法使用以下方法产生了我想要的东西,这不是最好的方法或最干净的方法,但是由于 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 上所做的测试