0
제스처를 클릭하고 길게 누르면 사용자가 이미지를 디스크에 업로드 할 수 있고 사용자는 동일한 제스처를 사용하여 이미지를 변경할 수있는 작업 이미지 피커가 있습니다. 유일한 문제는, 그러나, 나는 두 번 같은 뷰 (즉, 나는 두 개의 imageviews, 각각의 imageviews를 변경하는 두 개의 버튼을 가지고있다), 그리고 두 번째를 얻는 방법에 난처한 오전 할 필요가있다. 작업. 태그하나의보기에서 여러 이미지 피커 사용
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
//
// Saving into Documents folder
//
NSString* path = [NSHomeDirectory() stringByAppendingString:@"/Documents/first.png"];
BOOL ok = [[NSFileManager defaultManager] createFileAtPath:path
contents:nil attributes:nil];
if (!ok) {
NSLog(@"Error creating file %@", path);
} else {
NSFileHandle* myFileHandle = [NSFileHandle fileHandleForWritingAtPath:path];
[myFileHandle writeData:UIImagePNGRepresentation(info [UIImagePickerControllerOriginalImage])];
[myFileHandle closeFile];
}
//
// Loading from documents
//
NSFileHandle* myFileHandle = [NSFileHandle fileHandleForReadingAtPath:path];
UIImage* loadedImage = [UIImage imageWithData:[myFileHandle readDataToEndOfFile]];
self.chosenImage = loadedImage;
[self.imageView setImage:self.chosenImage];
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void) imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)onLongTile:(UILongPressGestureRecognizer *)gesture
{
switch ([gesture state]) {
case UIGestureRecognizerStateBegan:{
NSString *actionSheetTitle = @"Photo Options"; //Action Sheet Title
NSString *type = @"Upload Photo";
NSString *cancelTitle = @"Cancel";
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:actionSheetTitle
delegate:self
cancelButtonTitle:cancelTitle
destructiveButtonTitle:nil
otherButtonTitles:type, nil];
[actionSheet showInView:self.view]; }
}
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
NSString *buttonTitle = [actionSheet buttonTitleAtIndex:buttonIndex];
if ([buttonTitle isEqualToString:@"Photo"]) {
self.imagePicker = [[UIImagePickerController alloc] init];
self.imagePicker.delegate = self;
[self.imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:self.imagePicker animated:YES completion:nil];
}
}
업데이트 코드 :
여기내 현재 코드입니다 :
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
if (self.imageViewOne.tag == 100)
{
//
// Saving into Documents folder
//
NSString* path = [NSHomeDirectory() stringByAppendingString:@"/Documents/one.png"];
BOOL ok = [[NSFileManager defaultManager] createFileAtPath:path
contents:nil attributes:nil];
if (!ok) {
NSLog(@"Error creating file %@", path);
} else {
NSFileHandle* myFileHandle = [NSFileHandle fileHandleForWritingAtPath:path];
[myFileHandle writeData:UIImagePNGRepresentation(info [UIImagePickerControllerOriginalImage])];
[myFileHandle closeFile];
}
//
// Loading from documents
//
NSFileHandle* myFileHandle = [NSFileHandle fileHandleForReadingAtPath:path];
UIImage* loadedImage = [UIImage imageWithData:[myFileHandle readDataToEndOfFile]];
self.chosenImageOne = loadedImage;
[self.imageViewOne setImage:self.chosenImageOne];
[self dismissViewControllerAnimated:YES completion:nil];
}
if (self.imageViewTwo.tag == 200)
{
//
// Saving into Documents folder
//
NSString* path = [NSHomeDirectory() stringByAppendingString:@"/Documents/two.png"];
BOOL ok = [[NSFileManager defaultManager] createFileAtPath:path
contents:nil attributes:nil];
if (!ok) {
NSLog(@"Error creating file %@", path);
} else {
NSFileHandle* myFileHandle = [NSFileHandle fileHandleForWritingAtPath:path];
[myFileHandle writeData:UIImagePNGRepresentation(info [UIImagePickerControllerOriginalImage])];
[myFileHandle closeFile];
}
//
// Loading from documents
//
NSFileHandle* myFileHandle = [NSFileHandle fileHandleForReadingAtPath:path];
UIImage* loadedImage = [UIImage imageWithData:[myFileHandle readDataToEndOfFile]];
self.chosenImageTwo = loadedImage;
[self.imageViewTwo setImage:self.chosenImageTwo];
[self dismissViewControllerAnimated:YES completion:nil];
}
}
내가 사과, 내가 목표 - C 비교적 새로운 오전. imageViewOne 및 imageViewTwo를 지정된 태그로 설정하고 imagePickerController 메서드에서 구현하려고했습니다. 테스트를 마치면 어느 버튼 (즉, imageViewOne을 변경하는 버튼과 imageViewTwo를 변경하는 버튼)을 클릭 할 때마다 두 이미지에 동일한 이미지가 업로드됩니다. 내 원래 게시물에 내 업데이트 된 코드를 추가했습니다. 이 문제를 해결하는 데 큰 도움이 될 것입니다. 감사합니다. –
무엇을 하시겠습니까? 이미지 뷰 두 개가 맞습니까? 따라서 맨 위 버튼을 클릭하면 첫 번째 imageView에 이미지를로드하고 두 번째 버튼을 클릭하면 두 번째 imageView에 선택된 다른 이미지를로드할까요? – Anil
예, 정확하게. 15 chars –