From 3ac62fa9c85f52e67558a9073b739ef02ae2d0b9 Mon Sep 17 00:00:00 2001 From: CNlichao Date: Fri, 16 Oct 2015 16:31:16 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E8=AF=AD=E9=9F=B3=E6=92=AD=E6=94=BE?= =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=94=A4=E8=B5=B7=E7=AC=AC=E4=B8=89=E6=96=B9?= =?UTF-8?q?=E9=9F=B3=E4=B9=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 播放语音时,如果之前在播放音乐,播放或者录音完成,重新播放音乐 --- MessageDisplayKit/Classes/Common/XHAudioPlayerHelper.m | 3 +++ MessageDisplayKit/Classes/Common/XHVoiceRecordHelper.m | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/MessageDisplayKit/Classes/Common/XHAudioPlayerHelper.m b/MessageDisplayKit/Classes/Common/XHAudioPlayerHelper.m index 27f6873..caee081 100755 --- a/MessageDisplayKit/Classes/Common/XHAudioPlayerHelper.m +++ b/MessageDisplayKit/Classes/Common/XHAudioPlayerHelper.m @@ -37,6 +37,7 @@ - (void)stopAudio { if (_player && _player.isPlaying) { [_player stop]; } + [[AVAudioSession sharedInstance] setActive:NO withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:nil]; [[UIDevice currentDevice] setProximityMonitoringEnabled:NO]; if ([self.delegate respondsToSelector:@selector(didAudioPlayerStopPlay:)]) { [self.delegate didAudioPlayerStopPlay:_player]; @@ -180,11 +181,13 @@ - (void)sensorStateChange:(NSNotificationCenter *)notification { //黑屏 DLog(@"Device is close to user"); [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:nil]; + [[AVAudioSession sharedInstance] setActive:YES withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:nil]; } else { //没黑屏幕 DLog(@"Device is not close to user"); [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil]; + [[AVAudioSession sharedInstance] setActive:YES withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:nil]; if (!_player || !_player.isPlaying) { //没有播放了,也没有在黑屏状态下,就可以把距离传感器关了 [[UIDevice currentDevice] setProximityMonitoringEnabled:NO]; diff --git a/MessageDisplayKit/Classes/Common/XHVoiceRecordHelper.m b/MessageDisplayKit/Classes/Common/XHVoiceRecordHelper.m index 6612e87..124491f 100644 --- a/MessageDisplayKit/Classes/Common/XHVoiceRecordHelper.m +++ b/MessageDisplayKit/Classes/Common/XHVoiceRecordHelper.m @@ -90,6 +90,7 @@ - (void)cancelRecording { - (void)stopRecord { [self cancelRecording]; + [[AVAudioSession sharedInstance] setActive:NO withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:nil]; [self resetTimer]; } @@ -107,7 +108,7 @@ - (void)prepareRecordingWithPath:(NSString *)path prepareRecorderCompletion:(XHP } error = nil; - [audioSession setActive:YES error:&error]; + [audioSession setActive:YES withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:&error]; if(error) { DLog(@"audioSession: %@ %ld %@", [error domain], (long)[error code], [[error userInfo] description]); return; From 42161674c86b3afeb1f1a573a6cee7a8804c660a Mon Sep 17 00:00:00 2001 From: CNlichao Date: Fri, 16 Oct 2015 16:41:18 +0800 Subject: [PATCH 2/6] Revert "Merge remote-tracking branch 'xhzengAIB/master'" This reverts commit 5b3011dc0a33bce1de727732ad8df88ba8af966c, reversing changes made to 3ac62fa9c85f52e67558a9073b739ef02ae2d0b9. --- .travis.yml | 4 - .../contents.xcworkspacedata | 4 - .../xcschemes/MessageDisplayKit.xcscheme | 110 ------------------ 3 files changed, 118 deletions(-) delete mode 100644 .travis.yml delete mode 100644 Example/MessageDisplayKit/MessageDisplayKit.xcodeproj/project.xcworkspace/contents.xcworkspacedata delete mode 100644 Example/MessageDisplayKit/MessageDisplayKit.xcodeproj/xcshareddata/xcschemes/MessageDisplayKit.xcscheme diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 05c11a4..0000000 --- a/.travis.yml +++ /dev/null @@ -1,4 +0,0 @@ -osx_image: xcode7 -language: objective-c -xcode_workspace: Example/MessageDisplayKitWorkSpace.xcworkspace -xcode_schemes: MessageDisplayKit diff --git a/Example/MessageDisplayKit/MessageDisplayKit.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Example/MessageDisplayKit/MessageDisplayKit.xcodeproj/project.xcworkspace/contents.xcworkspacedata deleted file mode 100644 index 94b2795..0000000 --- a/Example/MessageDisplayKit/MessageDisplayKit.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ /dev/null @@ -1,4 +0,0 @@ - - - diff --git a/Example/MessageDisplayKit/MessageDisplayKit.xcodeproj/xcshareddata/xcschemes/MessageDisplayKit.xcscheme b/Example/MessageDisplayKit/MessageDisplayKit.xcodeproj/xcshareddata/xcschemes/MessageDisplayKit.xcscheme deleted file mode 100644 index 44cbf0a..0000000 --- a/Example/MessageDisplayKit/MessageDisplayKit.xcodeproj/xcshareddata/xcschemes/MessageDisplayKit.xcscheme +++ /dev/null @@ -1,110 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From 51857c85af7ac8f59326070a8f914ae57ece5529 Mon Sep 17 00:00:00 2001 From: CNlichao Date: Mon, 19 Oct 2015 14:32:59 +0800 Subject: [PATCH 3/6] =?UTF-8?q?fix=20#256=20=E5=8F=91=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E7=9A=84=E6=97=B6=E5=80=99=EF=BC=8C=E5=9B=BE=E7=89=87=E5=8F=AF?= =?UTF-8?q?=E8=83=BD=E5=8F=98=E5=BD=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../XHBubblePhotoImageView.m | 3 ++- .../MessageContentViews/XHMessageBubbleView.m | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/MessageDisplayKit/Classes/Views/MessageContentViews/XHBubblePhotoImageView.m b/MessageDisplayKit/Classes/Views/MessageContentViews/XHBubblePhotoImageView.m index 0aa1ec1..78e8cb6 100644 --- a/MessageDisplayKit/Classes/Views/MessageContentViews/XHBubblePhotoImageView.m +++ b/MessageDisplayKit/Classes/Views/MessageContentViews/XHBubblePhotoImageView.m @@ -72,7 +72,8 @@ - (void)configureMessagePhoto:(UIImage *)messagePhoto thumbnailUrl:(NSString *)t // if image not nil if (image) { // scale image - image = [image thumbnailImage:CGRectGetWidth(weakSelf.bounds) * 2 transparentBorder:0 cornerRadius:0 interpolationQuality:1.0]; + //避免多次缩放,图片变形 + //image = [image thumbnailImage:CGRectGetWidth(weakSelf.bounds) * 2 transparentBorder:0 cornerRadius:0 interpolationQuality:1.0]; dispatch_async(dispatch_get_main_queue(), ^{ // if image not nil if (image) { diff --git a/MessageDisplayKit/Classes/Views/MessageContentViews/XHMessageBubbleView.m b/MessageDisplayKit/Classes/Views/MessageContentViews/XHMessageBubbleView.m index d455fab..7de7e04 100644 --- a/MessageDisplayKit/Classes/Views/MessageContentViews/XHMessageBubbleView.m +++ b/MessageDisplayKit/Classes/Views/MessageContentViews/XHMessageBubbleView.m @@ -90,7 +90,23 @@ + (CGSize)neededSizeForText:(NSString *)text { // 计算图片实际大小 + (CGSize)neededSizeForPhoto:(UIImage *)photo { // 这里需要缩放后的size - CGSize photoSize = CGSizeMake(140, 140); + if (photo == nil) { + return CGSizeMake(140, 140); + } + // 这里需要缩放后的size + CGSize photoSize ; + + CGFloat photoWidth = photo.size.width; + CGFloat photoHeight = photo.size.height; + + CGFloat scalWidth = photoWidth / 140; + CGFloat scalHeight = photoHeight / 140; + + if (scalWidth > scalHeight) { + photoSize = CGSizeMake(photoWidth / scalWidth, photoHeight / scalWidth); + } else { + photoSize = CGSizeMake(photoWidth / scalHeight, photoHeight / scalHeight); + } return photoSize; } From 52fcc9d5606f7a4f0a7acc364d507ee633cdaff6 Mon Sep 17 00:00:00 2001 From: CNlichao Date: Mon, 19 Oct 2015 14:54:38 +0800 Subject: [PATCH 4/6] =?UTF-8?q?Revert=20"fix=20#256=20=E5=8F=91=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E7=9A=84=E6=97=B6=E5=80=99=EF=BC=8C=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E5=8F=AF=E8=83=BD=E5=8F=98=E5=BD=A2"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 51857c85af7ac8f59326070a8f914ae57ece5529. --- .../XHBubblePhotoImageView.m | 3 +-- .../MessageContentViews/XHMessageBubbleView.m | 18 +----------------- 2 files changed, 2 insertions(+), 19 deletions(-) diff --git a/MessageDisplayKit/Classes/Views/MessageContentViews/XHBubblePhotoImageView.m b/MessageDisplayKit/Classes/Views/MessageContentViews/XHBubblePhotoImageView.m index 78e8cb6..0aa1ec1 100644 --- a/MessageDisplayKit/Classes/Views/MessageContentViews/XHBubblePhotoImageView.m +++ b/MessageDisplayKit/Classes/Views/MessageContentViews/XHBubblePhotoImageView.m @@ -72,8 +72,7 @@ - (void)configureMessagePhoto:(UIImage *)messagePhoto thumbnailUrl:(NSString *)t // if image not nil if (image) { // scale image - //避免多次缩放,图片变形 - //image = [image thumbnailImage:CGRectGetWidth(weakSelf.bounds) * 2 transparentBorder:0 cornerRadius:0 interpolationQuality:1.0]; + image = [image thumbnailImage:CGRectGetWidth(weakSelf.bounds) * 2 transparentBorder:0 cornerRadius:0 interpolationQuality:1.0]; dispatch_async(dispatch_get_main_queue(), ^{ // if image not nil if (image) { diff --git a/MessageDisplayKit/Classes/Views/MessageContentViews/XHMessageBubbleView.m b/MessageDisplayKit/Classes/Views/MessageContentViews/XHMessageBubbleView.m index 7de7e04..d455fab 100644 --- a/MessageDisplayKit/Classes/Views/MessageContentViews/XHMessageBubbleView.m +++ b/MessageDisplayKit/Classes/Views/MessageContentViews/XHMessageBubbleView.m @@ -90,23 +90,7 @@ + (CGSize)neededSizeForText:(NSString *)text { // 计算图片实际大小 + (CGSize)neededSizeForPhoto:(UIImage *)photo { // 这里需要缩放后的size - if (photo == nil) { - return CGSizeMake(140, 140); - } - // 这里需要缩放后的size - CGSize photoSize ; - - CGFloat photoWidth = photo.size.width; - CGFloat photoHeight = photo.size.height; - - CGFloat scalWidth = photoWidth / 140; - CGFloat scalHeight = photoHeight / 140; - - if (scalWidth > scalHeight) { - photoSize = CGSizeMake(photoWidth / scalWidth, photoHeight / scalWidth); - } else { - photoSize = CGSizeMake(photoWidth / scalHeight, photoHeight / scalHeight); - } + CGSize photoSize = CGSizeMake(140, 140); return photoSize; } From 772dd5597edc3cbe271201be83d2923383a032a2 Mon Sep 17 00:00:00 2001 From: CNlichao Date: Fri, 23 Oct 2015 17:07:27 +0800 Subject: [PATCH 5/6] =?UTF-8?q?fix=20#256=20=E5=8F=91=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E7=9A=84=E6=97=B6=E5=80=99=EF=BC=8C=E5=9B=BE=E7=89=87=E5=8F=AF?= =?UTF-8?q?=E8=83=BD=E5=8F=98=E5=BD=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 之前方案只能处理本地图片,现在在显示的时候才处理,应该没问题了 --- .../XHBubblePhotoImageView.h | 2 +- .../XHBubblePhotoImageView.m | 64 +++++++++++++++---- .../MessageContentViews/XHMessageBubbleView.h | 5 ++ .../MessageContentViews/XHMessageBubbleView.m | 4 ++ 4 files changed, 62 insertions(+), 13 deletions(-) diff --git a/MessageDisplayKit/Classes/Views/MessageContentViews/XHBubblePhotoImageView.h b/MessageDisplayKit/Classes/Views/MessageContentViews/XHBubblePhotoImageView.h index a6ce3ad..d4dff87 100644 --- a/MessageDisplayKit/Classes/Views/MessageContentViews/XHBubblePhotoImageView.h +++ b/MessageDisplayKit/Classes/Views/MessageContentViews/XHBubblePhotoImageView.h @@ -10,7 +10,7 @@ #import "XHMessageBubbleFactory.h" #define kXHBubblePhotoMargin 8.0f // 上下左右的边距 - +#define kXHMaxBubblePhotoWidth 280.0f//最大图片宽度 @interface XHBubblePhotoImageView : UIView /** diff --git a/MessageDisplayKit/Classes/Views/MessageContentViews/XHBubblePhotoImageView.m b/MessageDisplayKit/Classes/Views/MessageContentViews/XHBubblePhotoImageView.m index 0aa1ec1..7dcb975 100644 --- a/MessageDisplayKit/Classes/Views/MessageContentViews/XHBubblePhotoImageView.m +++ b/MessageDisplayKit/Classes/Views/MessageContentViews/XHBubblePhotoImageView.m @@ -13,6 +13,7 @@ #import "XHConfigurationHelper.h" #import "XHMacro.h" +#import "XHMessageBubbleView.h" @interface XHBubblePhotoImageView () @@ -46,8 +47,10 @@ - (void)setMessagePhoto:(UIImage *)messagePhoto { - (void)configureMessagePhoto:(UIImage *)messagePhoto thumbnailUrl:(NSString *)thumbnailUrl originPhotoUrl:(NSString *)originPhotoUrl onBubbleMessageType:(XHBubbleMessageType)bubbleMessageType { self.bubbleMessageType = bubbleMessageType; - self.messagePhoto = messagePhoto; + if (messagePhoto) { + [self updateBubbleViewWithImage:messagePhoto]; + } if (thumbnailUrl) { WEAKSELF [self addSubview:self.activityIndicatorView]; @@ -68,25 +71,62 @@ - (void)configureMessagePhoto:(UIImage *)messagePhoto thumbnailUrl:(NSString *)t weakSelf.semaphore = nil; } } - // if image not nil if (image) { - // scale image - image = [image thumbnailImage:CGRectGetWidth(weakSelf.bounds) * 2 transparentBorder:0 cornerRadius:0 interpolationQuality:1.0]; - dispatch_async(dispatch_get_main_queue(), ^{ - // if image not nil - if (image) { - // show image - weakSelf.messagePhoto = image; - [weakSelf.activityIndicatorView stopAnimating]; - } - }); + [weakSelf updateBubbleViewWithImage:image]; } + } }]; } } +/** + * 根据图片更新BubbleView(主要设置图片大小尺寸) + */ +- (void)updateBubbleViewWithImage:(UIImage *)image { + + // scale image + CGSize size = [self needSizeForImage:image]; + image = [image resizedImage:size interpolationQuality:1.0]; + //图片太宽进行剪切,以免图片变形(截取中间的进行显示) + if (size.width > kXHMaxBubblePhotoWidth) { + image = [image croppedImage:CGRectMake((size.width - kXHMaxBubblePhotoWidth)/2, 0, kXHMaxBubblePhotoWidth, size.height)]; + size = CGSizeMake(kXHMaxBubblePhotoWidth, size.height); + } + + WEAKSELF + dispatch_async(dispatch_get_main_queue(), ^{ + // if image not nil + if (image) { + UIView *view = weakSelf.superview; + if ([view isKindOfClass:[XHMessageBubbleView class]]) { + XHMessageBubbleView * bubble = (XHMessageBubbleView *)view; + + bubble.sizeForBubblePhotoImageView = size; + [bubble layoutSubviews]; + } + // show image + weakSelf.messagePhoto = image; + [weakSelf.activityIndicatorView stopAnimating]; + } + }); +} + +/** + * 计算图片需要显示的大小,高度140计 + */ +- (CGSize)needSizeForImage:(UIImage *) photo { + // 这里需要缩放后的size + CGSize photoSize ; + + CGFloat photoWidth = photo.size.width; + CGFloat photoHeight = photo.size.height; + CGFloat realWidth = photoWidth * 140 / photoHeight; + photoSize = CGSizeMake(realWidth, 140); + return photoSize; +} + - (void)setFrame:(CGRect)frame { [super setFrame:frame]; if (self.semaphore) { diff --git a/MessageDisplayKit/Classes/Views/MessageContentViews/XHMessageBubbleView.h b/MessageDisplayKit/Classes/Views/MessageContentViews/XHMessageBubbleView.h index c363f1d..6f212b8 100644 --- a/MessageDisplayKit/Classes/Views/MessageContentViews/XHMessageBubbleView.h +++ b/MessageDisplayKit/Classes/Views/MessageContentViews/XHMessageBubbleView.h @@ -88,6 +88,11 @@ */ @property (nonatomic, strong) UIFont *font UI_APPEARANCE_SELECTOR; +/** + * 图片实际显示尺寸 + */ +@property (nonatomic,assign) CGSize sizeForBubblePhotoImageView; + /** * 初始化消息内容显示控件的方法 * diff --git a/MessageDisplayKit/Classes/Views/MessageContentViews/XHMessageBubbleView.m b/MessageDisplayKit/Classes/Views/MessageContentViews/XHMessageBubbleView.m index d455fab..acbcbdd 100644 --- a/MessageDisplayKit/Classes/Views/MessageContentViews/XHMessageBubbleView.m +++ b/MessageDisplayKit/Classes/Views/MessageContentViews/XHMessageBubbleView.m @@ -511,6 +511,10 @@ - (void)layoutSubviews { case XHBubbleMessageMediaTypeVideo: case XHBubbleMessageMediaTypeLocalPosition: { CGSize needPhotoSize = [XHMessageBubbleView neededSizeForPhoto:self.message.photo]; + if (!CGSizeEqualToSize(_sizeForBubblePhotoImageView,CGSizeZero)) { + needPhotoSize = _sizeForBubblePhotoImageView; + } + CGFloat paddingX = 0.0f; if (self.message.bubbleMessageType == XHBubbleMessageTypeSending) { paddingX = CGRectGetWidth(self.bounds) - needPhotoSize.width; From 49d9ae7737cac062280a5ce4bccae805f7713d12 Mon Sep 17 00:00:00 2001 From: lichao Date: Wed, 28 Oct 2015 16:33:45 +0800 Subject: [PATCH 6/6] Revert "Revert "Merge remote-tracking branch 'xhzengAIB/master'"" This reverts commit 42161674c86b3afeb1f1a573a6cee7a8804c660a. --- .travis.yml | 4 + .../contents.xcworkspacedata | 4 + .../xcschemes/MessageDisplayKit.xcscheme | 110 ++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 .travis.yml create mode 100644 Example/MessageDisplayKit/MessageDisplayKit.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 Example/MessageDisplayKit/MessageDisplayKit.xcodeproj/xcshareddata/xcschemes/MessageDisplayKit.xcscheme diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..05c11a4 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,4 @@ +osx_image: xcode7 +language: objective-c +xcode_workspace: Example/MessageDisplayKitWorkSpace.xcworkspace +xcode_schemes: MessageDisplayKit diff --git a/Example/MessageDisplayKit/MessageDisplayKit.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Example/MessageDisplayKit/MessageDisplayKit.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..94b2795 --- /dev/null +++ b/Example/MessageDisplayKit/MessageDisplayKit.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,4 @@ + + + diff --git a/Example/MessageDisplayKit/MessageDisplayKit.xcodeproj/xcshareddata/xcschemes/MessageDisplayKit.xcscheme b/Example/MessageDisplayKit/MessageDisplayKit.xcodeproj/xcshareddata/xcschemes/MessageDisplayKit.xcscheme new file mode 100644 index 0000000..44cbf0a --- /dev/null +++ b/Example/MessageDisplayKit/MessageDisplayKit.xcodeproj/xcshareddata/xcschemes/MessageDisplayKit.xcscheme @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +