Я создал приложение для камеры и библиотеки, где я выбираю изображение из своей библиотеки и показываю его на изображении. Но проблема, которая возникает, заключается в том, что после выбора изображения не отображается в imageView.Выбранное изображение не отображается
Вот мой код.
@interface ViewController()
{
BOOL isImageselected;
UIImageView *myImage;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Device has no camera"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[myAlertView show];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)addPhotoButton:(id)sender {
[UIView animateWithDuration:0.3 animations:^{
// animation here
self.pickerView.frame = CGRectMake(0.0, 443.0, 320.0, 125.0);
}];
}
- (IBAction)cameraButton:(id)sender {
[UIView animateWithDuration:0.3 animations:^{
// animation here
self.pickerView.frame = CGRectMake(0.0, 568.0, 320.0, 125.0);
}];
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
- (IBAction)uploadImageButton:(id)sender {
[UIView animateWithDuration:0.3 animations:^{
// animation here
self.pickerView.frame = CGRectMake(0.0, 568.0, 320.0, 125.0);
}];
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
myImage.image = chosenImage;
isImageselected = YES;
if (isImageselected == YES) {
myImage = [[UIImageView alloc]initWithFrame:CGRectMake(8.0, 8.0, 95.0, 95.0)];
self.addPhotoButton.frame = CGRectMake(106.0, 8.0, 95.0, 95.0);
}
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:NULL];
}
@end
Я думаю, что проблема происходит, когда я создаю ImageView динамически, но я не получаю точку, что является неправильным.
Не происходит. Я попытался выделить imageView в viewDidLoad, но я думаю, что imageView не создает. @Vladimir – iPeter
Добавили ли вы свое изображение для просмотра? [self.view addSubview: myImage]; –
Упс !!!! Это была главная проблема. @ Владимир Мне нужно учиться. :(Я такой новичок. :( – iPeter