Commit affe3e2a by 徐利超

update

parent e4443f6f
......@@ -24,7 +24,11 @@ NS_ASSUME_NONNULL_BEGIN
- (void)show;
- (void)dismiss;
- (void)updateToolBarWhenSameScreenAuthorityReq;
- (void)openMark;
- (void)closeMark;
- (void)updateToolBarWhenSameScreenAuthority:(BOOL)hasAuthority;
@end
......
......@@ -23,6 +23,7 @@
@property (nonatomic, strong) UIButton *undoBtn;
@property (nonatomic, assign) BOOL isMark;
@property (nonatomic, assign) BOOL hasAuthority;
@end
......@@ -63,10 +64,15 @@
}
- (void)updateToolBarWhenSameScreenAuthorityReq
- (void)updateToolBarWhenSameScreenAuthority:(BOOL)hasAuthority
{
[self.callBackBtn setTitle:@"收回同屏" forState:UIControlStateNormal];
[self updateToolBarViewWithshowArray:@[self.cancelBtn, self.markBtn, self.callBackBtn]];
self.hasAuthority = hasAuthority;
if (hasAuthority) {
[self updateToolBarViewWithshowArray:@[self.cancelBtn, self.markBtn]];
}else {
[self updateToolBarViewWithshowArray:@[self.cancelBtn, self.markBtn, self.callBackBtn]];
}
}
......@@ -102,14 +108,26 @@
}];
}
- (void)openMark
{
self.isMark = YES;
[self.cancelBtn setTitle:@"取消标注" forState:UIControlStateNormal];
[self updateToolBarViewWithshowArray:@[self.cancelBtn, self.clearBtn, self.undoBtn]];
}
- (void)closeMark
{
self.isMark = NO;
[self.cancelBtn setTitle:@"取消同屏" forState:UIControlStateNormal];
[self updateToolBarViewWithshowArray:@[self.cancelBtn, self.markBtn]];
}
#pragma mark - IBAction
- (void)cancelBtnTouched
{
if (self.isMark) {
self.isMark = NO;
[self closeMark];
[[YUNXINSameScreenManager shareInstance] closeMark];
[self.cancelBtn setTitle:@"取消同屏" forState:UIControlStateNormal];
[self updateToolBarViewWithshowArray:@[self.cancelBtn, self.markBtn]];
}else {
[self dismiss];
[[YUNXINSameScreenManager shareInstance] cancelSameScreencAction];
......@@ -129,10 +147,8 @@
- (void)markBtnTouched
{
self.isMark = YES;
[self openMark];
[[YUNXINSameScreenManager shareInstance] openMark];
[self.cancelBtn setTitle:@"取消标注" forState:UIControlStateNormal];
[self updateToolBarViewWithshowArray:@[self.cancelBtn, self.clearBtn, self.undoBtn]];
}
- (void)clearBtnTouched
......
......@@ -18,6 +18,8 @@
@property (nonatomic, strong) YUNXINDemoView *demoView;
@property (nonatomic, assign) BOOL isShow;
@end
@implementation YUNXINDemoViewController
......@@ -41,30 +43,63 @@
- (void)sameScreenBtnTouched
{
[_demoView show];
[[YUNXINSameScreenManager shareInstance] beginSameScreenAction];
_noticeLabel.hidden = YES;
_hangupBtn.hidden = YES;
_sameScreenBtn.hidden = YES;
// [_demoView show];
// [[YUNXINSameScreenManager shareInstance] beginSameScreenAction];
// _noticeLabel.hidden = YES;
// _hangupBtn.hidden = YES;
// _sameScreenBtn.hidden = YES;
// _isShow = YES;
[[YUNXINSameScreenManager shareInstance] requestForSameScreen];
}
#pragma mark - YUNXINSameScreenManagerDelegate
- (void)sameScreenRequestByUid:(NSString *)uid
{
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:[NSString stringWithFormat:@"%@请求同屏", uid] preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *approve = [UIAlertAction actionWithTitle:@"同意" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[[YUNXINSameScreenManager shareInstance] feedbackTheSameScreenRequset:YES];
}];
UIAlertAction *refuse = [UIAlertAction actionWithTitle:@"拒绝" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
[[YUNXINSameScreenManager shareInstance] feedbackTheSameScreenRequset:NO];
}];
[alertController addAction:approve];
[alertController addAction:refuse];
[self presentViewController:alertController animated:YES completion:nil];
}
- (void)sameScreenRequestFeedbackWithUid:(NSString *)uid isAgreed:(BOOL)isAgreed
{
if (isAgreed) {
if (!_isShow) {
[_demoView show];
[[YUNXINSameScreenManager shareInstance] beginSameScreenAction];
_noticeLabel.hidden = YES;
_hangupBtn.hidden = YES;
_sameScreenBtn.hidden = YES;
_isShow = YES;
}
}
}
- (void)sameScreenCloseView
{
[_demoView dismiss];
_noticeLabel.hidden = NO;
_hangupBtn.hidden = NO;
_sameScreenBtn.hidden = NO;
_isShow = NO;
}
- (void)sameScreenReceiveOperateReqWithUid:(NSString *)uid
{
_demoView.requesterUid = uid;
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:[NSString stringWithFormat:@"%@请求同屏操作", uid] preferredStyle:UIAlertControllerStyleAlert];
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:[NSString stringWithFormat:@"%@请求同屏操作权限", uid] preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *approve = [UIAlertAction actionWithTitle:@"同意" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[[YUNXINSameScreenManager shareInstance] approveTheSameScreenOperateAuthorityWithRequseterUid:uid isApproved:YES];
[self.demoView updateToolBarWhenSameScreenAuthorityReq];
[self.demoView updateToolBarWhenSameScreenAuthority:NO];
}];
UIAlertAction *refuse = [UIAlertAction actionWithTitle:@"拒绝" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
[[YUNXINSameScreenManager shareInstance] approveTheSameScreenOperateAuthorityWithRequseterUid:uid isApproved:NO];
......@@ -84,12 +119,28 @@
_sameScreenBtn.hidden = YES;
}
- (void)sameScreenReceiveOpenMarkNotification
{
[_demoView openMark];
}
- (void)sameScreenReceiveCloseMarkNotification
{
[_demoView closeMark];
}
- (void)sameScreenReceiveOperateAbandonNotification
{
[_demoView updateToolBarWhenSameScreenAuthority:YES];
}
#pragma mark - YUNXINDemoViewDelegate
- (void)demoViewDismiss
{
_noticeLabel.hidden = NO;
_hangupBtn.hidden = NO;
_sameScreenBtn.hidden = NO;
_isShow = NO;
}
#pragma mark - setter/getter
......
......@@ -16,6 +16,8 @@ NS_ASSUME_NONNULL_BEGIN
- (void)updateViewWithWebUrl:(NSString *)webUrl miniFlag:(NSString *)miniFlag;
- (void)reloadCurrentView;
- (void)updateWebViewWidth:(CGFloat)width height:(CGFloat)height;
- (void)updateViewWithContentY:(CGFloat)contentY;
- (void)updateWebViewWithWebAction:(NSDictionary *)param;
......@@ -25,8 +27,9 @@ NS_ASSUME_NONNULL_BEGIN
- (void)cancelMark;
- (void)addMarkWithParam:(NSDictionary *)paramDic;
- (void)clearCanvas;
- (void)undo;
- (void)updateMarkOperateStatus:(BOOL)couldMark;
- (void)undoSelf;
- (void)undoOther:(NSString *)uid;
- (void)destoryHeartBeat;
- (void)initHeartBeat;
......
......@@ -87,6 +87,11 @@ dispatch_async(dispatch_get_main_queue(), block);\
}
}
- (void)reloadCurrentView
{
[_webView reload];
}
- (void)updateWebViewWidth:(CGFloat)width height:(CGFloat)height
{
CGFloat wbWidth = width < self.viewFrame.size.width ? width : self.viewFrame.size.width;
......@@ -116,11 +121,6 @@ dispatch_async(dispatch_get_main_queue(), block);\
_webView.userInteractionEnabled = couldOperate;
}
- (void)updateMarkOperateStatus:(BOOL)couldMark
{
_webView.userInteractionEnabled = couldMark;
_scrawlView.userInteractionEnabled = couldMark;
}
#pragma mark - mark
......@@ -131,9 +131,6 @@ dispatch_async(dispatch_get_main_queue(), block);\
_scrawlView.delegate = self;
[self addSubview:_scrawlView];
}
if (self.isManager) {
_scrawlView.userInteractionEnabled = YES;
}
_scrawlView.hidden = NO;
}
......@@ -153,15 +150,21 @@ dispatch_async(dispatch_get_main_queue(), block);\
[_scrawlView clearAllPaint];
}
- (void)undo
- (void)undoSelf
{
[_scrawlView undo];
[_scrawlView undoSelf];
}
- (void)undoOther:(NSString *)uid
{
[_scrawlView undoOther:uid];
}
#pragma mark - heart
//取消心跳
- (void)destoryHeartBeat
{
[_webView.scrollView setContentOffset:CGPointMake(0, 0) animated:YES];
dispatch_main_async_safe(^{
if (self->heartBeat) {
if ([self->heartBeat respondsToSelector:@selector(isValid)]){
......@@ -221,6 +224,8 @@ dispatch_async(dispatch_get_main_queue(), block);\
completionHandler();
}
#pragma mark - setter/getter
- (WKWebView *)webView
{
......
......@@ -17,6 +17,17 @@ NS_ASSUME_NONNULL_BEGIN
@optional
//同屏相关
/// 收到开始同屏请求 (非管理员使用)
/// @param uid 发起者云信token
- (void)sameScreenRequestByUid:(NSString *)uid;
/// 请求同屏操作反馈 (管理员使用)
/// @param uid 反馈者云信token
/// @param isAgreed 是否同意
- (void)sameScreenRequestFeedbackWithUid:(NSString *)uid isAgreed:(BOOL)isAgreed;
/// 在该回调内添加或展示同屏页面
/// @param showUrl 展示的url
/// @param miniFlag 小程序对应的Flag
......@@ -39,6 +50,13 @@ NS_ASSUME_NONNULL_BEGIN
/// 收到非管理员主动放弃操作权限的通知 (管理员使用)
- (void)sameScreenReceiveOperateAbandonNotification;
/// 收到打开标注通知
- (void)sameScreenReceiveOpenMarkNotification;
/// 收到关闭标注通知
- (void)sameScreenReceiveCloseMarkNotification;
@end
@interface YUNXINSameScreenManager : NSObject
......@@ -74,6 +92,13 @@ NS_ASSUME_NONNULL_BEGIN
- (void)updateSameScreenViewWithWebUrl:(NSString *)webUrl miniFlag:(NSString *)miniFlag;
/// 请求同屏
- (void)requestForSameScreen;
/// 回复是否同意同屏
/// @param isAgreed 是否同意
- (void)feedbackTheSameScreenRequset:(BOOL)isAgreed;
/// 开始同屏
- (void)beginSameScreenAction;
......@@ -107,7 +132,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)undoCanvas;
/// 发送自定义通知消息
/// 发送自定义通知消息 (忽略)
/// @param param param
/// @param action action
- (void)sendCustomSysMsgWithParam:(NSDictionary *)param action:(NSString *)action;
......
......@@ -66,6 +66,7 @@
- (void)updateSameScreenViewWithWebUrl:(NSString *)webUrl miniFlag:(NSString *)miniFlag
{
[self.webView updateViewWithWebUrl:webUrl miniFlag:miniFlag];
[_webView initHeartBeat];
}
- (void)sameScreenSynchronizeViewSize
......@@ -78,7 +79,16 @@
NSDictionary *attachment = msgContent;
NSString *action = [attachment objectForKey:@"action"];
NSDictionary *param = [attachment objectForKey:@"param"];
if ([action isEqualToString:SameScreenSyncSize]) {
if ([action isEqualToString:SameScreenOpenReq]) {
if ([_delegate respondsToSelector:@selector(sameScreenRequestByUid:)]) {
[_delegate sameScreenRequestByUid:param[@"uid"]];
}
}else if ([action isEqualToString:SameScreenOpenAnswer]) {
BOOL isAgree = [param[@"agree"] isEqualToString:@"1"];
if ([_delegate respondsToSelector:@selector(sameScreenRequestFeedbackWithUid:isAgreed:)]) {
[_delegate sameScreenRequestFeedbackWithUid:param[@"uid"] isAgreed:isAgree];
}
}else if ([action isEqualToString:SameScreenSyncSize]) {
CGFloat remoteUesrWidth = [param[@"width"] floatValue];
CGFloat remoteUesrHeight = [param[@"height"] floatValue];
[self.webView updateWebViewWidth:remoteUesrWidth height:remoteUesrHeight];
......@@ -87,6 +97,7 @@
[_delegate sameScreenShowViewWithShowUrl:param[@"url"] miniFlag:param[@"flag"]];
}
}else if ([action isEqualToString:SameScreenCloseView]) {
[_webView destoryHeartBeat];
if ([_delegate respondsToSelector:@selector(sameScreenCloseView)]) {
[_delegate sameScreenCloseView];
}
......@@ -101,26 +112,44 @@
}else if ([action isEqualToString:SameScreenOperateCallback]) {
[self dealWithOperateCallBack:param];
}else if ([action isEqualToString:SameScreenOperateGiveUp]) {
[self dealWithOperateGiveUp];
}else if ([action isEqualToString:SameScreenOpenMark]) {
[_webView openMark];
if ([_delegate respondsToSelector:@selector(sameScreenReceiveOpenMarkNotification)]) {
[_delegate sameScreenReceiveOpenMarkNotification];
}
}else if ([action isEqualToString:SameScreenCloseMark]) {
[_webView cancelMark];
if ([_delegate respondsToSelector:@selector(sameScreenReceiveCloseMarkNotification)]) {
[_delegate sameScreenReceiveCloseMarkNotification];
}
}else if ([action isEqualToString:SameScreenSyncMarkPath]) {
[_webView addMarkWithParam:param];
}else if ([action isEqualToString:SameScreenClearCanvas]) {
[_webView clearCanvas];
}else if ([action isEqualToString:SameScreenUndoPreviousPath]) {
[_webView undo];
[_webView undoOther:param[@"uid"]];
}
}
- (void)requestForSameScreen
{
[self sendCustomSysMsgWithParam:@{@"uid":[[[NIMSDK sharedSDK] loginManager] currentAccount]} action:SameScreenOpenReq];
}
- (void)feedbackTheSameScreenRequset:(BOOL)isAgreed
{
NSString *agree = isAgreed ? @"1": @"0";
[self sendCustomSysMsgWithParam:@{@"uid":[[[NIMSDK sharedSDK] loginManager] currentAccount], @"agree":agree} action:SameScreenOpenAnswer];
}
- (void)beginSameScreenAction
{
if (_webView) {
[self sameScreenSynchronizeViewSize];
[self sendCustomSysMsgWithParam:[_webView getShowDic] action:SameScreenOpenView];
[_webView updateOperateStatus:YES];
[_webView initHeartBeat];
}
}
......@@ -178,27 +207,11 @@
- (void)undoCanvas
{
[_webView undo];
[self sendCustomSysMsgWithParam:@{} action:SameScreenUndoPreviousPath];
[_webView undoSelf];
[self sendCustomSysMsgWithParam:@{@"uid": [[[NIMSDK sharedSDK] loginManager] currentAccount]} action:SameScreenUndoPreviousPath];
}
- (void)requestForMarkOperateAuthority
{
[self sendCustomSysMsgWithParam:@{@"uid":[[[NIMSDK sharedSDK] loginManager] currentAccount]} action:SameScreenMarkReq];
}
- (void)approveTheMarkOperateAuthorityWithRequseterUid:(NSString *)requesterUid isApproved:(BOOL)isApproved
{
NSString *approved = isApproved ? @"1" : @"0";
[_webView updateMarkOperateStatus:!isApproved];
[self sendCustomSysMsgWithParam:@{@"uid": requesterUid, @"approve":approved} action:SameScreenMarkAnswer];
}
- (void)callbackTheRequsterMarkOperateAuthorityWithRequsterUid:(NSString *)requesterUid
{
[_webView updateMarkOperateStatus:YES];
[self sendCustomSysMsgWithParam:@{@"uid": requesterUid} action:SameScreenMarkCallback];
}
#pragma mark - sendCustomSysMsg
......
......@@ -37,10 +37,10 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (void)clearAllPaint;
/**
* 撤销一步
*/
- (void)undo;
/// 撤销自己上一步
- (void)undoSelf;
/// 撤销别人上一步
- (void)undoOther:(NSString *)uid;
@end
......
......@@ -14,6 +14,8 @@
/// 线条layer数组
@property (nonatomic, strong) NSMutableArray *pathLinesArr;
/// 线条layer数组
@property (nonatomic, strong) NSMutableArray *myPathLinesArr;
/// 当前真在绘画的轨迹笔
@property (nonatomic, strong) YWPaintPath *path;
/// 当前正在绘画的轨迹坐标点集合
......@@ -75,7 +77,8 @@
slayer.lineWidth = path.lineWidth;
[self.layer addSublayer:slayer];
_slayer = slayer;
[[self mutableArrayValueForKey:@"pathLinesArr"] addObject:_slayer];
NSDictionary *layerDic = @{@"uid":[[[NIMSDK sharedSDK] loginManager] currentAccount], @"layer":_slayer};
[[self mutableArrayValueForKey:@"myPathLinesArr"] addObject:layerDic];
}
}
......@@ -98,13 +101,14 @@
{
//send arr
if ([_delegate respondsToSelector:@selector(sendScrawlViewParam:)]) {
[_delegate sendScrawlViewParam:@{@"pathColor":self.colorHexStr, @"pathArr":self.pointArr}];
[_delegate sendScrawlViewParam:@{@"pathColor":self.colorHexStr, @"pathArr":self.pointArr, @"uid":[[[NIMSDK sharedSDK] loginManager] currentAccount]}];
}
}
- (void)drawLineWithPathData:(NSDictionary *)paramDic
{
if (paramDic && [[paramDic objectForKey:@"pathArr"] isKindOfClass:[NSArray class]]) {
NSString *uid = [paramDic objectForKey:@"uid"];
NSString *pathColor = [paramDic objectForKey:@"pathColor"];
NSArray *pathArr = [[NSArray alloc] initWithArray:[paramDic objectForKey:@"pathArr"]];
CGPoint startP = CGPointMake([[[pathArr firstObject] objectForKey:@"x"] floatValue], [[[pathArr firstObject] objectForKey:@"y"] floatValue]);
......@@ -115,7 +119,7 @@
CGPoint moveP = CGPointMake([[[pathArr objectAtIndex:i] objectForKey:@"x"] floatValue], [[[pathArr objectAtIndex:i] objectForKey:@"y"] floatValue]);
[path addLineToPoint:moveP];
}
_path = path;
// _path = path;
CAShapeLayer *slayer = [CAShapeLayer layer];
slayer.path = path.CGPath;
slayer.backgroundColor = [UIColor clearColor].CGColor;
......@@ -125,11 +129,12 @@
slayer.strokeColor = [self colorWithHexStr:pathColor].CGColor;
slayer.lineWidth = path.lineWidth;
[self.layer addSublayer:slayer];
_slayer = slayer;
[self.pathLinesArr addObject:_slayer];
// _slayer = slayer;
NSDictionary *layerDic = @{@"uid":uid, @"layer":slayer};
[self.pathLinesArr addObject:layerDic];
//主线程刷新UI
dispatch_async(dispatch_get_main_queue(), ^{
[self.layer addSublayer:self.slayer];
[self.layer addSublayer:slayer];
});
}
}
......@@ -137,23 +142,52 @@
/// 清屏
- (void)clearAllPaint
{
if (!self.pathLinesArr.count) {
if (!self.pathLinesArr.count && !self.myPathLinesArr.count) {
return;
}
[self.pathLinesArr makeObjectsPerformSelector:@selector(removeFromSuperlayer)];
for (NSDictionary *layerDic in self.pathLinesArr) {
CAShapeLayer *layer = layerDic[@"layer"];
[layer removeFromSuperlayer];
}
for (NSDictionary *layerDic in self.myPathLinesArr) {
CAShapeLayer *layer = layerDic[@"layer"];
[layer removeFromSuperlayer];
}
[[self mutableArrayValueForKey:@"pathLinesArr"] removeAllObjects];
[[self mutableArrayValueForKey:@"myPathLinesArr"] removeAllObjects];
}
/// 撤销上一步
- (void)undo
- (void)undoSelf
{
if (!self.pathLinesArr.count) {
if (!self.myPathLinesArr.count) {
return;
}
NSDictionary *layerDic = self.myPathLinesArr.lastObject;
CAShapeLayer *layer = layerDic[@"layer"];
[layer removeFromSuperlayer];
[[self mutableArrayValueForKey:@"myPathLinesArr"] removeLastObject];
}
- (void)undoOther:(NSString *)uid
{
[self.pathLinesArr.lastObject removeFromSuperlayer];
[[self mutableArrayValueForKey:@"pathLinesArr"] removeLastObject];
NSMutableArray *uidArr = [NSMutableArray array];
for (NSDictionary *layerDic in self.pathLinesArr) {
if ([layerDic[@"uid"] isEqualToString:uid]) {
[uidArr addObject:layerDic];
}
}
if (!uidArr.count) {
return;
}
NSDictionary *layerDic = uidArr.lastObject;
CAShapeLayer *layer = layerDic[@"layer"];
[layer removeFromSuperlayer];
[[self mutableArrayValueForKey:@"pathLinesArr"] removeObject:layerDic];
}
#pragma mark - color
......@@ -200,6 +234,15 @@
return _pathLinesArr;
}
- (NSMutableArray *)myPathLinesArr
{
if (!_myPathLinesArr) {
_myPathLinesArr = [[NSMutableArray alloc] init];
}
return _myPathLinesArr;
}
- (NSMutableArray *)pointArr {
if (!_pointArr) {
_pointArr = [[NSMutableArray alloc]init];
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册登录 后发表评论