Skip to content

Commit 403d862

Browse files
guangyaoguangyao
authored andcommitted
增加大图片
1 parent af39106 commit 403d862

File tree

14 files changed

+327
-10
lines changed

14 files changed

+327
-10
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// DWOrigImgView.h
3+
// RCTAuroraIMUI
4+
//
5+
// Created by Dowin on 2017/8/29.
6+
// Copyright © 2017年 HXHG. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
#define screenW [UIScreen mainScreen].bounds.size.width
11+
#define screenH [UIScreen mainScreen].bounds.size.height
12+
@interface DWOrigImgView : UIView
13+
+ (instancetype)origImgViewWithDict:(NSDictionary *)dict;
14+
@end
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
//
2+
// DWOrigImgView.m
3+
// RCTAuroraIMUI
4+
//
5+
// Created by Dowin on 2017/8/29.
6+
// Copyright © 2017年 HXHG. All rights reserved.
7+
//
8+
9+
#import "DWOrigImgView.h"
10+
#import "UIView+Extend.h"
11+
#import "MyCacheImageView.h"
12+
13+
14+
@interface DWOrigImgView (){
15+
MyCacheImageView *imgView;
16+
UIPinchGestureRecognizer *pinchGest;
17+
UIPanGestureRecognizer *panGest;
18+
UITapGestureRecognizer *tapGest;
19+
CGRect orginFrame;
20+
UIButton *downBtn;
21+
22+
}
23+
24+
@end
25+
26+
@implementation DWOrigImgView
27+
28+
- (void)dealloc{
29+
[imgView removeGestureRecognizer:pinchGest];
30+
[imgView removeGestureRecognizer:panGest];
31+
[self removeGestureRecognizer:tapGest];
32+
}
33+
34+
+ (instancetype)origImgViewWithDict:(NSDictionary *)dict{
35+
DWOrigImgView *orgView = [[DWOrigImgView alloc]init];
36+
[orgView setupImgViewWithDict:dict];
37+
return orgView;
38+
}
39+
40+
- (void)setupImgViewWithDict:(NSDictionary *)dict{
41+
NSString *thumbPath = [dict objectForKey:@"thumbPath"];
42+
NSString *strUrl = [dict objectForKey:@"url"];
43+
UIImage *placeImg = [UIImage imageWithData:[NSData dataWithContentsOfFile:thumbPath]];
44+
[imgView setImageURL:strUrl placeImage:placeImg];
45+
NSNumber *numW = [dict objectForKey:@"imageWidth"];
46+
NSNumber *numH = [dict objectForKey:@"imageHeight"];
47+
CGFloat multiple = numW.floatValue / numH.floatValue;
48+
CGFloat imgW = screenW;
49+
CGFloat imgH = imgW / multiple;
50+
CGFloat imgY = 0;
51+
if (imgH < screenH) {
52+
imgY = (screenH-imgH)*0.5;
53+
}
54+
imgView.frame = CGRectMake(0, imgY, imgW, imgH);
55+
orginFrame = imgView.frame;
56+
}
57+
58+
59+
- (instancetype)initWithFrame:(CGRect)frame{
60+
if (self = [super initWithFrame:frame]) {
61+
self.backgroundColor = [UIColor blackColor];
62+
self.userInteractionEnabled = YES;
63+
[self addContentView];
64+
}
65+
return self;
66+
}
67+
68+
- (void)addContentView{
69+
imgView = [[MyCacheImageView alloc]init];
70+
imgView.contentMode = UIViewContentModeScaleAspectFit;
71+
imgView.userInteractionEnabled = YES;
72+
imgView.multipleTouchEnabled = YES;
73+
[self addSubview:imgView];
74+
pinchGest = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(clickPinchView:)];
75+
[imgView addGestureRecognizer:pinchGest];
76+
panGest = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(clickPanView:)];
77+
[imgView addGestureRecognizer:panGest];
78+
79+
tapGest = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickTapGest)];
80+
[self addGestureRecognizer:tapGest];
81+
82+
CGFloat btnWH = 35;
83+
CGFloat btnX = screenW - btnWH - 20;
84+
CGFloat btnY = screenH - btnWH - 20;
85+
downBtn = [[UIButton alloc]initWithFrame:CGRectMake(btnX, btnY, btnWH, btnWH)];
86+
[downBtn setBackgroundImage:[UIImage imageNamed:@"download"] forState:UIControlStateNormal];
87+
[downBtn addTarget:self action:@selector(clickDownLoadBtn) forControlEvents:UIControlEventTouchUpInside];
88+
[self addSubview:downBtn];
89+
[self performSelector:@selector(delayMethod) withObject:nil afterDelay:3.0];
90+
91+
}
92+
93+
- (void)delayMethod{
94+
[UIView animateWithDuration:0.5 animations:^{
95+
downBtn.alpha -= 1;
96+
} completion:^(BOOL finished) {
97+
downBtn.hidden = YES;
98+
downBtn.alpha = 1;
99+
}];
100+
101+
}
102+
103+
- (void)clickDownLoadBtn{
104+
UIImageWriteToSavedPhotosAlbum(imgView.image, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
105+
}
106+
107+
- (void)image: (UIImage *) image didFinishSavingWithError: (NSError *) error contextInfo: (void *) contextInfo{
108+
NSString *msg = nil ;
109+
if(error != NULL){
110+
msg = @"保存图片失败" ;
111+
}else{
112+
msg = @"保存图片成功" ;
113+
}
114+
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:msg message:@"" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
115+
[alert show];
116+
}
117+
118+
119+
- (void)clickPinchView:(UIPinchGestureRecognizer *)gest{
120+
UIView *view = gest.view;
121+
if (gest.state == UIGestureRecognizerStateBegan || gest.state == UIGestureRecognizerStateChanged) {
122+
view.transform = CGAffineTransformScale(view.transform, gest.scale, gest.scale);
123+
gest.scale = 1;
124+
}
125+
if (gest.state == UIGestureRecognizerStateEnded) {
126+
if (view.frame.size.width < screenW) {
127+
CGFloat tmpW = screenW - view.width;
128+
CGFloat tmpH = orginFrame.size.height - view.height;
129+
[UIView animateWithDuration:0.3 animations:^{
130+
view.width += tmpW;
131+
view.height += tmpH;
132+
view.x -= tmpW*0.5;
133+
view.y -= tmpH*0.5;
134+
135+
} completion:^(BOOL finished) {
136+
view.frame = orginFrame;
137+
}];
138+
}
139+
if (view.width > 1.5 * screenW) {
140+
CGFloat maxH = view.height - orginFrame.size.height*1.5;
141+
CGFloat maxW = view.width - screenW*1.5;
142+
[UIView animateWithDuration:0.3 animations:^{
143+
view.width -= maxW;
144+
view.height -= maxH;
145+
view.x += maxW*0.5;
146+
view.y += maxH*0.5;
147+
}];
148+
}
149+
}
150+
}
151+
152+
- (void)clickPanView:(UIPanGestureRecognizer *)gest{
153+
UIView *view = gest.view;
154+
if (gest.state == UIGestureRecognizerStateBegan || gest.state == UIGestureRecognizerStateChanged) {
155+
CGPoint translation = [gest translationInView:view.superview];
156+
[view setCenter:(CGPoint){view.center.x + translation.x, view.center.y + translation.y}];
157+
[gest setTranslation:CGPointZero inView:view.superview];
158+
}
159+
if (gest.state == UIGestureRecognizerStateEnded) {
160+
if (view.x>0) {
161+
CGFloat tmpX = view.x;
162+
[UIView animateWithDuration:0.3 animations:^{
163+
view.x -= tmpX;
164+
} completion:^(BOOL finished) {
165+
view.x = 0;
166+
}];
167+
}else if((screenW-view.x)>view.width){
168+
CGFloat tmpx = screenW - view.x - view.width;
169+
[UIView animateWithDuration:0.3 animations:^{
170+
view.x += tmpx;
171+
} completion:^(BOOL finished) {
172+
view.x = screenW - view.width;
173+
}];
174+
}
175+
if (view.height > screenH) {
176+
if ((view.height - screenH + view.y)<0) {
177+
CGFloat tmpH = screenH - view.height - view.y;
178+
[UIView animateWithDuration:0.3 animations:^{
179+
view.y += tmpH;
180+
}];
181+
}else if (view.y > 0){
182+
CGFloat tmpH = view.y ;
183+
[UIView animateWithDuration:0.3 animations:^{
184+
view.y -= tmpH;
185+
}];
186+
}
187+
}else{
188+
CGFloat tmpH = view.y - (screenH - view.height)*0.5;;
189+
[UIView animateWithDuration:0.3 animations:^{
190+
view.y -= tmpH;
191+
}];
192+
}
193+
}
194+
}
195+
196+
- (void)clickTapGest{
197+
[self removeFromSuperview];
198+
}
199+
200+
@end

ios/RCTAuroraIMUI/DWCustomView/InputView/DWAudioRecorderManager.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#import <AVFoundation/AVFoundation.h>
1111
#import <AudioToolbox/AudioToolbox.h>
1212

13+
#define maxRecordTime 59
14+
1315
@interface DWAudioRecorderManager()<AVAudioRecorderDelegate>{
1416
CGFloat timeCount;
1517
}
@@ -138,9 +140,9 @@ - (void)detectionVoice
138140
{
139141
timeCount = timeCount + 0.05;
140142
NSLog(@"timeCount:%f",timeCount);
141-
if (timeCount < 60) {
143+
if (timeCount < maxRecordTime) {
142144
if (timeCount > 49) {
143-
[[NSNotificationCenter defaultCenter]postNotificationName:@"RecordLongNotification" object:@(60 - timeCount)];
145+
[[NSNotificationCenter defaultCenter]postNotificationName:@"RecordLongNotification" object:@(maxRecordTime - timeCount)];
144146
}
145147

146148
// 刷新音量数据

ios/RCTAuroraIMUI/DWCustomView/InputView/DWRecordButton.m

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,17 @@
77
//
88

99
#import "DWRecordButton.h"
10+
#import <AVFoundation/AVFoundation.h>
1011

1112
#define kGetColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1]
1213

14+
@interface DWRecordButton (){
15+
BOOL isAuthorized;//录音权限
16+
}
17+
18+
@end
19+
20+
1321
@implementation DWRecordButton
1422

1523
- (instancetype)init
@@ -70,10 +78,45 @@ - (void)setButtonStateWithCancel
7078
[self setTitle:strCancel forState:UIControlStateNormal];
7179
}
7280

81+
//判断录音权限
82+
- (BOOL)canRecord
83+
{
84+
isAuthorized = NO;
85+
AVAuthorizationStatus AVstatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio];//麦克风权限
86+
switch (AVstatus) {
87+
//允许状态
88+
case AVAuthorizationStatusAuthorized:
89+
isAuthorized = YES;
90+
NSLog(@"Authorized");
91+
break;
92+
//不允许状态,可以弹出一个alertview提示用户在隐私设置中开启权限
93+
case AVAuthorizationStatusDenied:
94+
NSLog(@"Denied");
95+
break;
96+
//未知,第一次申请权限
97+
case AVAuthorizationStatusNotDetermined:
98+
NSLog(@"not Determined");
99+
//此应用程序没有被授权访问,可能是家长控制权限
100+
case AVAuthorizationStatusRestricted:{
101+
NSLog(@"Restricted");
102+
NSString *tips = @"请在iPhone的”设置-隐私-照片“选项中,允许App访问你的麦克风";
103+
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:tips delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
104+
[alert show];
105+
}
106+
break;
107+
default:
108+
NSLog(@"default");
109+
break;
110+
}
111+
return isAuthorized;
112+
}
113+
114+
73115
#pragma mark -- 事件方法回调
74116
- (void)recordTouchDown
75117
{
76-
if ([self.delegate respondsToSelector:@selector(recordTouchDownAction:)]) {
118+
// [self canRecord];
119+
if ([self.delegate respondsToSelector:@selector(recordTouchDownAction:)] ) {
77120
[self.delegate recordTouchDownAction:self];
78121
}
79122
}
@@ -87,14 +130,14 @@ - (void)recordTouchUpOutside
87130

88131
- (void)recordTouchUpInside
89132
{
90-
if ([self.delegate respondsToSelector:@selector(recordTouchUpInsideAction:)]) {
133+
if ([self.delegate respondsToSelector:@selector(recordTouchUpInsideAction:)] ) {
91134
[self.delegate recordTouchUpInsideAction:self];
92135
}
93136
}
94137

95138
- (void)recordTouchDragEnter
96139
{
97-
if ([self.delegate respondsToSelector:@selector(recordTouchDragEnterAction:)]) {
140+
if ([self.delegate respondsToSelector:@selector(recordTouchDragEnterAction:)] ) {
98141
[self.delegate recordTouchDragEnterAction:self];
99142
}
100143
}
@@ -108,7 +151,7 @@ - (void)recordTouchDragInside
108151

109152
- (void)recordTouchDragOutside
110153
{
111-
if ([self.delegate respondsToSelector:@selector(recordTouchDragOutsideAction:)]) {
154+
if ([self.delegate respondsToSelector:@selector(recordTouchDragOutsideAction:)] ) {
112155
[self.delegate recordTouchDragOutsideAction:self];
113156
}
114157
}

ios/RCTAuroraIMUI/DWCustomView/MyCacheImageView.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@
1414

1515
- (void)setImageURL:(NSString *)URL placeholderImage:(NSString *)imageName;
1616

17+
- (void)setImageURL:(NSString *)URL placeImage:(UIImage *)image;
18+
1719
@end

ios/RCTAuroraIMUI/DWCustomView/MyCacheImageView.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,9 @@ - (void)setImageURL:(NSString *)URL placeholderImage:(NSString *)imageName{
1919
[self sd_setImageWithURL:[NSURL URLWithString:URL] placeholderImage:[UIImage imageNamed:imageName]];
2020
}
2121

22+
- (void)setImageURL:(NSString *)URL placeImage:(UIImage *)image{
23+
24+
[self sd_setImageWithURL:[NSURL URLWithString:URL] placeholderImage:image];
25+
}
2226

2327
@end

ios/RCTAuroraIMUI/IMUICommon/Controllers/IMUIAudioPlayerHelper.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,28 @@ public class IMUIAudioPlayerHelper: NSObject {
3333

3434
override init() {
3535
super.init()
36+
NotificationCenter.default.addObserver(self, selector: #selector(sensorStateChange(notification:)), name: NSNotification.Name(rawValue: "UIDeviceProximityStateDidChangeNotification"), object: nil)
3637

3738
}
3839

40+
func sensorStateChange(notification:Notification) {
41+
if UIDevice.current.proximityState {
42+
do {
43+
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord)
44+
45+
}catch let error as NSError {
46+
print("set category fail \(error)")
47+
}
48+
}else{
49+
do {
50+
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
51+
52+
}catch let error as NSError {
53+
print("set category fail \(error)")
54+
}
55+
}
56+
}
57+
3958
open func playAudioWithData(_ voiceData:Data, progressCallback: @escaping ProgressCallback, finishCallBack: @escaping FinishCallback) {
4059
do {
4160
self.playProgressCallback = progressCallback
@@ -89,6 +108,9 @@ public class IMUIAudioPlayerHelper: NSObject {
89108
self.delegate?.didAudioPlayerStopPlay(self.player)
90109
}
91110
}
111+
deinit {
112+
NotificationCenter.default.removeObserver(self)
113+
}
92114
}
93115

94116

ios/RCTAuroraIMUI/IMUIMessageCollectionView/M80AttributedLabel/M80AttributedLabel/M80AttributedLabel.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,7 @@ - (BOOL)onLabelClick:(CGPoint)point
990990
if (url)
991991
{
992992
// [[UIApplication sharedApplication] openURL:url];
993+
NSLog(@"-----------");
993994
NSString *strUrl = [NSString stringWithFormat:@"%@",url];
994995
[[NSNotificationCenter defaultCenter] postNotificationName:@"OpenUrlNotification" object:@{@"url":strUrl,@"label":self}];
995996
}

0 commit comments

Comments
 (0)