Skip to content
This repository has been archived by the owner on Aug 14, 2019. It is now read-only.

Commit

Permalink
handle iOS 7 and 8 specific issues. close #5221. close #544. ref #484.
Browse files Browse the repository at this point in the history
  • Loading branch information
jessesquires committed Oct 11, 2014
1 parent 18fc6ec commit 7ef5b4b
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 14 deletions.
6 changes: 6 additions & 0 deletions JSQMessages.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -150,6 +151,8 @@
88445B3F19E1B4470014F889 /* JSQLocationMediaItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JSQLocationMediaItem.m; sourceTree = "<group>"; };
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 = "<group>"; };
886FFD2D19E9A65D00EB8485 /* UIDevice+JSQMessages.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIDevice+JSQMessages.m"; sourceTree = "<group>"; };
8885734819DE540400E89D20 /* DemoSettingsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DemoSettingsViewController.h; sourceTree = "<group>"; };
8885734919DE540400E89D20 /* DemoSettingsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DemoSettingsViewController.m; sourceTree = "<group>"; };
8885734B19DE55D000E89D20 /* NSUserDefaults+DemoSettings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSUserDefaults+DemoSettings.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down
28 changes: 28 additions & 0 deletions JSQMessagesViewController/Categories/UIDevice+JSQMessages.h
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions JSQMessagesViewController/Categories/UIDevice+JSQMessages.m
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@

#import "JSQMessagesKeyboardController.h"

#import "UIDevice+JSQMessages.h"


NSString * const JSQMessagesKeyboardControllerNotificationKeyboardDidChangeFrame = @"JSQMessagesKeyboardControllerNotificationKeyboardDidChangeFrame";
NSString * const JSQMessagesKeyboardControllerUserInfoKeyKeyboardDidChangeFrame = @"JSQMessagesKeyboardControllerUserInfoKeyKeyboardDidChangeFrame";

Expand Down Expand Up @@ -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);
Expand Down
29 changes: 18 additions & 11 deletions JSQMessagesViewController/Controllers/JSQMessagesViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

#import "NSString+JSQMessages.h"
#import "UIColor+JSQMessages.h"
#import "UIDevice+JSQMessages.h"


static void * kJSQMessagesKeyValueObservingContext = &kJSQMessagesKeyValueObservingContext;
Expand Down Expand Up @@ -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];
}
}
Expand Down Expand Up @@ -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:
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#import "JSQMessagesCollectionViewLayoutAttributes.h"

#import "UIView+JSQMessages.h"
#import "UIDevice+JSQMessages.h"


@interface JSQMessagesCollectionViewCell ()
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7ef5b4b

Please sign in to comment.