diff --git a/JSQMessages.xcodeproj/project.pbxproj b/JSQMessages.xcodeproj/project.pbxproj index 7b768d11c..1892389f6 100644 --- a/JSQMessages.xcodeproj/project.pbxproj +++ b/JSQMessages.xcodeproj/project.pbxproj @@ -30,6 +30,7 @@ 88445B4419E1B5110014F889 /* MapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 88445B4319E1B5110014F889 /* MapKit.framework */; }; 88445B4519E1B5210014F889 /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 88445B4119E1B50B0014F889 /* CoreLocation.framework */; }; 88445B4619E1B5290014F889 /* MapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 88445B4319E1B5110014F889 /* MapKit.framework */; }; + 886FFD2E19E9A65D00EB8485 /* UIDevice+JSQMessages.m in Sources */ = {isa = PBXBuildFile; fileRef = 886FFD2D19E9A65D00EB8485 /* UIDevice+JSQMessages.m */; }; 8885734A19DE540400E89D20 /* DemoSettingsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8885734919DE540400E89D20 /* DemoSettingsViewController.m */; }; 8885734D19DE55D000E89D20 /* NSUserDefaults+DemoSettings.m in Sources */ = {isa = PBXBuildFile; fileRef = 8885734C19DE55D000E89D20 /* NSUserDefaults+DemoSettings.m */; }; 88A25F3719D8DF2500924534 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 88A25F2D19D8DF2500924534 /* AppDelegate.m */; }; @@ -150,6 +151,8 @@ 88445B3F19E1B4470014F889 /* JSQLocationMediaItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JSQLocationMediaItem.m; sourceTree = ""; }; 88445B4119E1B50B0014F889 /* CoreLocation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreLocation.framework; path = System/Library/Frameworks/CoreLocation.framework; sourceTree = SDKROOT; }; 88445B4319E1B5110014F889 /* MapKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MapKit.framework; path = System/Library/Frameworks/MapKit.framework; sourceTree = SDKROOT; }; + 886FFD2C19E9A65D00EB8485 /* UIDevice+JSQMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIDevice+JSQMessages.h"; sourceTree = ""; }; + 886FFD2D19E9A65D00EB8485 /* UIDevice+JSQMessages.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIDevice+JSQMessages.m"; sourceTree = ""; }; 8885734819DE540400E89D20 /* DemoSettingsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DemoSettingsViewController.h; sourceTree = ""; }; 8885734919DE540400E89D20 /* DemoSettingsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DemoSettingsViewController.m; sourceTree = ""; }; 8885734B19DE55D000E89D20 /* NSUserDefaults+DemoSettings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSUserDefaults+DemoSettings.h"; sourceTree = ""; }; @@ -479,6 +482,8 @@ 88A25F5819D8E01A00924534 /* NSString+JSQMessages.m */, 88A25F5919D8E01A00924534 /* UIColor+JSQMessages.h */, 88A25F5A19D8E01A00924534 /* UIColor+JSQMessages.m */, + 886FFD2C19E9A65D00EB8485 /* UIDevice+JSQMessages.h */, + 886FFD2D19E9A65D00EB8485 /* UIDevice+JSQMessages.m */, 88A25F5B19D8E01A00924534 /* UIImage+JSQMessages.h */, 88A25F5C19D8E01A00924534 /* UIImage+JSQMessages.m */, 88A25F5D19D8E01A00924534 /* UIView+JSQMessages.h */, @@ -872,6 +877,7 @@ 88A25FE019D8E0C400924534 /* DemoModelData.m in Sources */, 88A25F3C19D8DF2500924534 /* main.m in Sources */, 88A25F3719D8DF2500924534 /* AppDelegate.m in Sources */, + 886FFD2E19E9A65D00EB8485 /* UIDevice+JSQMessages.m in Sources */, 88A25FB619D8E01A00924534 /* NSString+JSQMessages.m in Sources */, 88A25FCC19D8E01A00924534 /* JSQMessagesCollectionViewCellIncoming.m in Sources */, 88A25FBE19D8E01A00924534 /* JSQMessagesBubbleImageFactory.m in Sources */, diff --git a/JSQMessagesViewController/Categories/UIDevice+JSQMessages.h b/JSQMessagesViewController/Categories/UIDevice+JSQMessages.h new file mode 100644 index 000000000..e3ee4b544 --- /dev/null +++ b/JSQMessagesViewController/Categories/UIDevice+JSQMessages.h @@ -0,0 +1,28 @@ +// +// Created by Jesse Squires +// http://www.jessesquires.com +// +// +// Documentation +// http://cocoadocs.org/docsets/JSQMessagesViewController +// +// +// GitHub +// https://github.com/jessesquires/JSQMessagesViewController +// +// +// License +// Copyright (c) 2014 Jesse Squires +// Released under an MIT license: http://opensource.org/licenses/MIT +// + +@import UIKit; + +@interface UIDevice (JSQMessages) + +/** + * @return Whether or not the current device is running a version of iOS before 8.0. + */ ++ (BOOL)jsq_isCurrentDeviceBeforeiOS8; + +@end diff --git a/JSQMessagesViewController/Categories/UIDevice+JSQMessages.m b/JSQMessagesViewController/Categories/UIDevice+JSQMessages.m new file mode 100644 index 000000000..cb3178705 --- /dev/null +++ b/JSQMessagesViewController/Categories/UIDevice+JSQMessages.m @@ -0,0 +1,29 @@ +// +// Created by Jesse Squires +// http://www.jessesquires.com +// +// +// Documentation +// http://cocoadocs.org/docsets/JSQMessagesViewController +// +// +// GitHub +// https://github.com/jessesquires/JSQMessagesViewController +// +// +// License +// Copyright (c) 2014 Jesse Squires +// Released under an MIT license: http://opensource.org/licenses/MIT +// + +#import "UIDevice+JSQMessages.h" + +@implementation UIDevice (JSQMessages) + ++ (BOOL)jsq_isCurrentDeviceBeforeiOS8 +{ + // iOS < 8.0 + return [[UIDevice currentDevice].systemVersion compare:@"8.0.0" options:NSNumericSearch] == NSOrderedAscending; +} + +@end diff --git a/JSQMessagesViewController/Controllers/JSQMessagesKeyboardController.m b/JSQMessagesViewController/Controllers/JSQMessagesKeyboardController.m index 655e6bf7d..11be9e77f 100644 --- a/JSQMessagesViewController/Controllers/JSQMessagesKeyboardController.m +++ b/JSQMessagesViewController/Controllers/JSQMessagesKeyboardController.m @@ -23,6 +23,9 @@ #import "JSQMessagesKeyboardController.h" +#import "UIDevice+JSQMessages.h" + + NSString * const JSQMessagesKeyboardControllerNotificationKeyboardDidChangeFrame = @"JSQMessagesKeyboardControllerNotificationKeyboardDidChangeFrame"; NSString * const JSQMessagesKeyboardControllerUserInfoKeyKeyboardDidChangeFrame = @"JSQMessagesKeyboardControllerUserInfoKeyKeyboardDidChangeFrame"; @@ -307,8 +310,12 @@ - (void)jsq_handlePanGestureRecognizer:(UIPanGestureRecognizer *)pan // system keyboard is added to a new UIWindow, need to operate in window coordinates // also, keyboard always slides from bottom of screen, not the bottom of a view CGFloat contextViewWindowHeight = CGRectGetHeight(self.contextView.window.frame); - if (UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) { - contextViewWindowHeight = CGRectGetWidth(self.contextView.window.frame); + + if ([UIDevice jsq_isCurrentDeviceBeforeiOS8]) { + // handle iOS 7 bug when rotating to landscape + if (UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) { + contextViewWindowHeight = CGRectGetWidth(self.contextView.window.frame); + } } CGFloat keyboardViewHeight = CGRectGetHeight(self.keyboardView.frame); diff --git a/JSQMessagesViewController/Controllers/JSQMessagesViewController.m b/JSQMessagesViewController/Controllers/JSQMessagesViewController.m index 1ee14a936..c4679e336 100644 --- a/JSQMessagesViewController/Controllers/JSQMessagesViewController.m +++ b/JSQMessagesViewController/Controllers/JSQMessagesViewController.m @@ -40,6 +40,7 @@ #import "NSString+JSQMessages.h" #import "UIColor+JSQMessages.h" +#import "UIDevice+JSQMessages.h" static void * kJSQMessagesKeyValueObservingContext = &kJSQMessagesKeyValueObservingContext; @@ -235,7 +236,7 @@ - (void)viewDidAppear:(BOOL)animated [self jsq_addActionToInteractivePopGestureRecognizer:YES]; [self.keyboardController beginListeningForKeyboard]; - if (self.snapshotView) { + if ([UIDevice jsq_isCurrentDeviceBeforeiOS8]) { [self.snapshotView removeFromSuperview]; } } @@ -757,20 +758,23 @@ - (void)jsq_handleInteractivePopGestureRecognizer:(UIGestureRecognizer *)gesture switch (gestureRecognizer.state) { case UIGestureRecognizerStateBegan: { - if (self.snapshotView) { + if ([UIDevice jsq_isCurrentDeviceBeforeiOS8]) { [self.snapshotView removeFromSuperview]; } [self.keyboardController endListeningForKeyboard]; - [self.inputToolbar.contentView.textView resignFirstResponder]; - [UIView animateWithDuration:0.0 - animations:^{ - [self jsq_setToolbarBottomLayoutGuideConstant:0.0f]; - }]; - UIView *snapshot = [self.view snapshotViewAfterScreenUpdates:YES]; - [self.view addSubview:snapshot]; - self.snapshotView = snapshot; + if ([UIDevice jsq_isCurrentDeviceBeforeiOS8]) { + [self.inputToolbar.contentView.textView resignFirstResponder]; + [UIView animateWithDuration:0.0 + animations:^{ + [self jsq_setToolbarBottomLayoutGuideConstant:0.0f]; + }]; + + UIView *snapshot = [self.view snapshotViewAfterScreenUpdates:YES]; + [self.view addSubview:snapshot]; + self.snapshotView = snapshot; + } } break; case UIGestureRecognizerStateChanged: @@ -779,7 +783,10 @@ - (void)jsq_handleInteractivePopGestureRecognizer:(UIGestureRecognizer *)gesture case UIGestureRecognizerStateEnded: case UIGestureRecognizerStateFailed: [self.keyboardController beginListeningForKeyboard]; - [self.snapshotView removeFromSuperview]; + + if ([UIDevice jsq_isCurrentDeviceBeforeiOS8]) { + [self.snapshotView removeFromSuperview]; + } break; default: break; diff --git a/JSQMessagesViewController/Views/JSQMessagesCollectionViewCell.m b/JSQMessagesViewController/Views/JSQMessagesCollectionViewCell.m index b22c7e1ae..4f4ecbb3d 100644 --- a/JSQMessagesViewController/Views/JSQMessagesCollectionViewCell.m +++ b/JSQMessagesViewController/Views/JSQMessagesCollectionViewCell.m @@ -23,6 +23,7 @@ #import "JSQMessagesCollectionViewLayoutAttributes.h" #import "UIView+JSQMessages.h" +#import "UIDevice+JSQMessages.h" @interface JSQMessagesCollectionViewCell () @@ -222,7 +223,10 @@ - (void)setSelected:(BOOL)selected - (void)setBounds:(CGRect)bounds { [super setBounds:bounds]; - self.contentView.frame = bounds; + + if ([UIDevice jsq_isCurrentDeviceBeforeiOS8]) { + self.contentView.frame = bounds; + } } #pragma mark - Setters