我正在尝试制作一个具有类似于VSCO应用程序的导入页面的应用程序。但是在用户从图库中选择多张照片后,我无法确定如何在视图中显示所有图片,最大应为10张照片。
要获得图像,我使用了此代码,它对于选择一张图片非常有用:
Texture2D tex;
void Start() {
tex = new Texture2D(1, 1);
//get the color printed by calling:
StartCoroutine(CaptureTempArea());
}
IEnumerator CaptureTempArea() {
yield return new WaitForEndOfFrame();
Vector2 pos = UICamera.lastEventPosition;
tex.ReadPixels(new Rect(pos.x, pos.y, 1, 1), 0, 0);
tex.Apply();
Color color = tex.GetPixel(0, 0);
Debug.Log(ColorToHex(color));
}
void OnDestroy() {
Destroy(tex);
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
[self dismissViewControllerAnimated:false completion:nil];
// transfer to the main screen
dispatch_async(dispatch_get_main_queue(), ^{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
PreviewVC *prevVC = (PreviewVC *)[storyboard instantiateViewControllerWithIdentifier:@"PreviewVC"];
passedImage = image;
prevVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:prevVC animated:true completion:nil];
});
}
在使用预览视图显示导入的照片之后,可以对其进行编辑:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
[self dismissViewControllerAnimated:false completion:nil];
// Go to the Main Screen
dispatch_async(dispatch_get_main_queue(), ^{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
PreviewVC *prevVC = (PreviewVC *)[storyboard instantiateViewControllerWithIdentifier:@"PreviewVC"];
// Passing Image to Preview VC
passedImage = image;
prevVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:prevVC animated:true completion:nil];
});
答案 0 :(得分:0)
如果您的想法是在PreviewVC
中构建多个图像,则让其启动选择器并将其保留图像阵列作为属性。该图像数组又成为预览vc中表视图的数据源。粗略的轮廓...
// in PreviewVC.m
// in the private interface
@property (nonatomic, weak) IBOutlet UITableView *tableView; // attach this in IB, don't forget to set datasource to this vc
@property (nonatomic, strong) NSArray *images;
- (void)userDidPressPickImageButton:(id)sender {
// launch image picker vc from here
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
[self dismissViewControllerAnimated:false completion:nil];
image = [self imageWithImage:image scaledToSize:someSize]; // move this method here, too
// here's the key
[self.images addObject:image];
[self.tableView reloadData];
}
让表视图数据源回答self.images.count
以获得numberOfRows,当然,cellForRow必须使用self.images[indexPath.row]
配置单元格