Я пытаюсь реализовать полноэкранный UIImagePickerController в своем приложении. Я не мог представить контроллер представления в viewDidLoad
, потому что presenting view controllers on detached view controllers is discouraged
. Однако мой viewDidAppear
вызывается бесконечно, а контроллер средства выбора изображений добавляется, а затем исчезает с экрана при каждом вызове. Я попытался отправить в основную очередь, но это не решило проблему.
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
ipc = [[UIImagePickerController alloc] init];
ipc.delegate = self;
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
ipc.sourceType = UIImagePickerControllerSourceTypeCamera;
ipc.showsCameraControls = NO;
CGAffineTransform translate = CGAffineTransformMakeTranslation(0.0, 71.0);
ipc.cameraViewTransform = translate;
CGAffineTransform scale = CGAffineTransformScale(translate, 1.333333, 1.333333);
ipc.cameraViewTransform = scale;
ipc.showsCameraControls = NO;
ipc.tabBarController.tabBar.hidden = YES;
ipc.allowsEditing = NO;
[self presentViewController:ipc animated:YES completion:nil];
}
}
#pragma mark - ImagePickerController Delegate
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage* theImage = [info objectForKey:UIImagePickerControllerOriginalImage];
if( picker.sourceType == UIImagePickerControllerSourceTypeCamera )
{
UIImageWriteToSavedPhotosAlbum(theImage, nil, nil, nil);
}
int height = -1;
if([[NSUserDefaults standardUserDefaults] integerForKey:@"reduce_image"] == 0){
height = 640;
} else if ([[NSUserDefaults standardUserDefaults] integerForKey:@"reduce_image"] == 1) {
height = 1024;
} else {
height = 1600;
}
UIImage* resizedImageForUpload = [UtilityFunctions scaleAndRotateImage:theImage maxResolution:height];
NSData* imageDataForUpload = UIImageJPEGRepresentation(resizedImageForUpload, 1); // reduced image! //
NSString *userDataset = [UtilityFunctions retrieveFromUserDefaults:@"dataset"];
[self didPickImage:imageDataForUpload atLocation:currentLocation
userDataset: userDataset];
[picker dismissViewControllerAnimated:YES completion:nil];
[mLocationManager stopUpdatingLocation];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
/*navigate to home tab*/
[picker dismissViewControllerAnimated:YES completion:nil];
self.tabBarController.tabBar.hidden = NO;
[self.tabBarController setSelectedIndex:0];
}
dismissViewControllerAnimated
. Я думаю, что он был уволен случайно. - person mschmidt   schedule 07.12.2017viewWillDisappear
, из-за чего мы попали в этот цикл! - person maddie   schedule 07.12.2017