From f6747e1ffc31faa33444e612d3c74a0f77412905 Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Mon, 4 Apr 2016 14:14:15 +0200 Subject: [PATCH] contact: rotate photo when invalid rotation --- Classes/ChatConversationView.m | 9 +++++++++ Classes/ContactDetailsTableView.m | 6 +++--- Classes/ContactDetailsView.m | 9 +++++++++ Classes/SideMenuView.m | 9 +++++++++ 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/Classes/ChatConversationView.m b/Classes/ChatConversationView.m index f13002729..f7e941385 100644 --- a/Classes/ChatConversationView.m +++ b/Classes/ChatConversationView.m @@ -556,6 +556,15 @@ static UICompositeViewDescription *compositeDescription = nil; #pragma mark ImagePickerDelegate - (void)imagePickerDelegateImage:(UIImage *)image info:(NSDictionary *)info { + // When getting image from the camera, it may be 90° rotated due to orientation + // (image.imageOrientation = UIImageOrientationRight). Just rotate it to be face up. + if (image.imageOrientation != UIImageOrientationUp) { + UIGraphicsBeginImageContextWithOptions(image.size, false, image.scale); + [image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)]; + image = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); + } + // Dismiss popover on iPad if (IPAD) { [VIEW(ImagePickerView).popoverController dismissPopoverAnimated:TRUE]; diff --git a/Classes/ContactDetailsTableView.m b/Classes/ContactDetailsTableView.m index 7f57ce47a..a61abc33a 100644 --- a/Classes/ContactDetailsTableView.m +++ b/Classes/ContactDetailsTableView.m @@ -79,10 +79,10 @@ added = [_contact addEmail:value]; } - if (added && animated) { + if (added) { NSUInteger count = [self getSectionData:section].count; [tableview insertRowsAtIndexPaths:@[ [NSIndexPath indexPathForRow:count - 1 inSection:section] ] - withRowAnimation:UITableViewRowAnimationFade]; + withRowAnimation:animated ? UITableViewRowAnimationFade : UITableViewRowAnimationNone]; } } @@ -223,7 +223,7 @@ [self removeEmptyEntry:self.tableView section:section animated:NO]; // the section is empty -> remove titles - if ([[self getSectionData:section] count] == 0 && animated) { + if ([[self getSectionData:section] count] == 0) { [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:animated ? UITableViewRowAnimationFade : UITableViewRowAnimationNone]; diff --git a/Classes/ContactDetailsView.m b/Classes/ContactDetailsView.m index 09bdf64c9..f0d857aab 100644 --- a/Classes/ContactDetailsView.m +++ b/Classes/ContactDetailsView.m @@ -310,6 +310,15 @@ static UICompositeViewDescription *compositeDescription = nil; #pragma mark - Image picker delegate - (void)imagePickerDelegateImage:(UIImage *)image info:(NSDictionary *)info { + // When getting image from the camera, it may be 90° rotated due to orientation + // (image.imageOrientation = UIImageOrientationRight). Just rotate it to be face up. + if (image.imageOrientation != UIImageOrientationUp) { + UIGraphicsBeginImageContextWithOptions(image.size, false, image.scale); + [image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)]; + image = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); + } + // Dismiss popover on iPad if (IPAD) { [VIEW(ImagePickerView).popoverController dismissPopoverAnimated:TRUE]; diff --git a/Classes/SideMenuView.m b/Classes/SideMenuView.m index 699299135..f084a900f 100644 --- a/Classes/SideMenuView.m +++ b/Classes/SideMenuView.m @@ -99,6 +99,15 @@ #pragma mark - Image picker delegate - (void)imagePickerDelegateImage:(UIImage *)image info:(NSDictionary *)info { + // When getting image from the camera, it may be 90° rotated due to orientation + // (image.imageOrientation = UIImageOrientationRight). Just rotate it to be face up. + if (image.imageOrientation != UIImageOrientationUp) { + UIGraphicsBeginImageContextWithOptions(image.size, false, image.scale); + [image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)]; + image = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); + } + // Dismiss popover on iPad if (IPAD) { [VIEW(ImagePickerView).popoverController dismissPopoverAnimated:TRUE];