修复了房间半屏私聊崩溃的问题
This commit is contained in:
@@ -7,6 +7,8 @@
|
||||
//
|
||||
|
||||
#import "XCCurrentVCStackManager.h"
|
||||
|
||||
NSString * const kRoomChatPushViewKey = @"kRoomChatPushViewKey";
|
||||
@implementation XCCurrentVCStackManager
|
||||
|
||||
+ (instancetype)shareManager {
|
||||
@@ -21,22 +23,7 @@
|
||||
|
||||
- (UIViewController *)getCurrentVC {
|
||||
///兼容房间内私聊的
|
||||
UIWindow * currentWindow;
|
||||
for (int i = 0; i < [UIApplication sharedApplication].windows.count; i++) {
|
||||
UIWindow * window = [[UIApplication sharedApplication].windows objectAtIndex:i];
|
||||
if(window.tag == 1000) {
|
||||
currentWindow = window;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (currentWindow) {
|
||||
[currentWindow resignKeyWindow];
|
||||
[currentWindow.rootViewController.navigationController popViewControllerAnimated:YES];
|
||||
[currentWindow.superview removeFromSuperview];
|
||||
currentWindow.rootViewController = nil;
|
||||
currentWindow.windowLevel = -1;
|
||||
currentWindow = nil;
|
||||
}
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:kRoomChatPushViewKey object:nil];
|
||||
|
||||
UIViewController *rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
|
||||
UIViewController *currentVC = [self getCurrentVCFrom:rootViewController];
|
||||
|
@@ -179,6 +179,12 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)viewDidLayoutSubviews{
|
||||
if (self.openType == SessionListOpenTypeRoom) {
|
||||
self.view.frame = CGRectMake(0, 0, KScreenWidth, kHalfScreenHeight);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)initData {
|
||||
NIMUser * user = [[NIMSDK sharedSDK].userManager userInfo:self.session.sessionId];
|
||||
if (user) {
|
||||
@@ -314,6 +320,17 @@
|
||||
}
|
||||
|
||||
- (void)sessionNavView:(SessionNavView *)view didClickBack:(UIButton *)sender {
|
||||
if (self.openType == SessionListOpenTypeRoom) {
|
||||
CATransition *transition = [CATransition animation];
|
||||
transition.duration = 0.3f;
|
||||
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
|
||||
transition.type = kCATransitionPush;
|
||||
transition.subtype = kCATransitionFromLeft;
|
||||
[self.view.superview.layer addAnimation:transition forKey:nil];
|
||||
[self removeFromParentViewController];
|
||||
[self.view removeFromSuperview];
|
||||
return;
|
||||
}
|
||||
[self.navigationController popViewControllerAnimated:YES];
|
||||
}
|
||||
|
||||
|
@@ -21,6 +21,9 @@ typedef NS_ENUM(NSUInteger, SessionListOpenType) {
|
||||
@interface SessionListViewController : BaseViewController<JXCategoryListContentViewDelegate>
|
||||
|
||||
- (instancetype)initWithType:(SessionListOpenType)type;
|
||||
/** 控制器 因为房间内聊天没有控制器去push 或者做其他的操作*/
|
||||
@property (nonatomic, weak) UIViewController * mainController;
|
||||
|
||||
|
||||
@end
|
||||
|
||||
|
@@ -161,11 +161,26 @@ NSString * const kMessageShowReadDotKey = @"kMessageShowReadDotKey";
|
||||
[self.navigationController pushViewController:findNewVC animated:YES];
|
||||
return;
|
||||
}
|
||||
|
||||
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
||||
NIMRecentSession *recentSession = self.recentSessions[indexPath.row];
|
||||
SessionViewController *vc = [[SessionViewController alloc] initWithSession:recentSession.session];
|
||||
vc.openType = self.openType;
|
||||
[self.navigationController pushViewController:vc animated:YES];
|
||||
if (self.openType == SessionListOpenTypeRoom) {
|
||||
NIMRecentSession *recentSession = self.recentSessions[indexPath.row];
|
||||
SessionViewController * sessionVC =[[SessionViewController alloc] initWithSession:recentSession.session];
|
||||
sessionVC.openType = self.openType;
|
||||
CATransition *transition = [CATransition animation];
|
||||
transition.duration = 0.3f;
|
||||
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
|
||||
transition.type = kCATransitionPush;
|
||||
transition.subtype = kCATransitionFromRight;
|
||||
[self.mainController.view.layer addAnimation:transition forKey:nil];
|
||||
[self.mainController.view addSubview:sessionVC.view];
|
||||
[self.mainController addChildViewController:sessionVC];
|
||||
} else {
|
||||
NIMRecentSession *recentSession = self.recentSessions[indexPath.row];
|
||||
SessionViewController *vc = [[SessionViewController alloc] initWithSession:recentSession.session];
|
||||
vc.openType = self.openType;
|
||||
[self.navigationController pushViewController:vc animated:YES];
|
||||
}
|
||||
}
|
||||
|
||||
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
|
||||
|
@@ -21,6 +21,8 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
@property (nonatomic,assign) ContactUseingType type;
|
||||
///代理
|
||||
@property (nonatomic,weak) id<XPMineAttentionViewControllerDelegate> delegate;
|
||||
/** 控制器 因为房间内聊天没有控制器去push 或者做其他的操作*/
|
||||
@property (nonatomic, weak) UIViewController * mainController;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
@@ -163,7 +163,14 @@
|
||||
if (self.type == ContactUseingType_In_Room) {
|
||||
SessionViewController * sessionVC = [[SessionViewController alloc] initWithSession:[NIMSession session:fansInfoModel.uid type:NIMSessionTypeP2P]];
|
||||
sessionVC.openType = SessionListOpenTypeRoom;
|
||||
[self.navigationController pushViewController:sessionVC animated:YES];
|
||||
CATransition *transition = [CATransition animation];
|
||||
transition.duration = 0.3f;
|
||||
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
|
||||
transition.type = kCATransitionPush;
|
||||
transition.subtype = kCATransitionFromRight;
|
||||
[self.mainController.view.layer addAnimation:transition forKey:nil];
|
||||
[self.mainController addChildViewController:sessionVC];
|
||||
[self.mainController.view addSubview:sessionVC.view];
|
||||
} else if(self.type == ContactUseingType_Share){
|
||||
if (self.delegate && [self.delegate respondsToSelector:@selector(xPMineAttentionViewController:didSelectItem:)]) {
|
||||
[self.delegate xPMineAttentionViewController:self didSelectItem:fansInfoModel];
|
||||
|
@@ -58,6 +58,7 @@
|
||||
- (void)initSubViews {
|
||||
[self.view addSubview:self.titleView];
|
||||
[self.view addSubview:self.listContainerView];
|
||||
|
||||
}
|
||||
|
||||
- (void)initSubViewConstraints {
|
||||
@@ -81,12 +82,16 @@
|
||||
// 根据下标 index 返回对应遵守并实现 `JXCategoryListContentViewDelegate` 协议的列表实例
|
||||
- (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index {
|
||||
if (index == 0) {
|
||||
// [self addChildViewController:self.sessionListVC];
|
||||
return self.sessionListVC;
|
||||
}else if (index == 1) {
|
||||
// [self addChildViewController:self.friendVC];
|
||||
return self.friendVC;
|
||||
} else if(index == 2) {
|
||||
// [self addChildViewController:self.fansVC];
|
||||
return self.fansVC;
|
||||
} else {
|
||||
// [self addChildViewController:self.attentionVC];
|
||||
return self.attentionVC;
|
||||
}
|
||||
}
|
||||
@@ -139,6 +144,7 @@
|
||||
- (SessionListViewController *)sessionListVC {
|
||||
if (!_sessionListVC) {
|
||||
_sessionListVC = [[SessionListViewController alloc] initWithType:SessionListOpenTypeRoom];
|
||||
_sessionListVC.mainController = self;
|
||||
}
|
||||
return _sessionListVC;
|
||||
}
|
||||
@@ -147,6 +153,7 @@
|
||||
if (!_attentionVC) {
|
||||
_attentionVC = [[XPMineAttentionViewController alloc] init];
|
||||
_attentionVC.type = ContactUseingType_In_Room;
|
||||
_attentionVC.mainController = self;
|
||||
}
|
||||
return _attentionVC;
|
||||
}
|
||||
@@ -155,6 +162,7 @@
|
||||
if (!_friendVC) {
|
||||
_friendVC = [[XPMineFriendViewController alloc] init];
|
||||
_friendVC.type = ContactUseingType_In_Room;
|
||||
_friendVC.mainController = self;
|
||||
}
|
||||
return _friendVC;
|
||||
}
|
||||
@@ -163,6 +171,7 @@
|
||||
if (!_fansVC) {
|
||||
_fansVC = [[XPMineFansViewController alloc] init];
|
||||
_fansVC.type = ContactUseingType_In_Room;
|
||||
_fansVC.mainController = self;
|
||||
}
|
||||
return _fansVC;
|
||||
}
|
||||
|
@@ -21,6 +21,8 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
@property (nonatomic,assign) ContactUseingType type;
|
||||
///代理
|
||||
@property (nonatomic,weak) id<XPMineFansViewControllerDelegate> delegate;
|
||||
/** 控制器 因为房间内聊天没有控制器去push 或者做其他的操作*/
|
||||
@property (nonatomic, weak) UIViewController * mainController;
|
||||
|
||||
@end
|
||||
|
||||
|
@@ -173,7 +173,14 @@
|
||||
if (self.type == ContactUseingType_In_Room) {
|
||||
SessionViewController * sessionVC = [[SessionViewController alloc] initWithSession:[NIMSession session:fansInfoModel.uid type:NIMSessionTypeP2P]];
|
||||
sessionVC.openType = SessionListOpenTypeRoom;
|
||||
[self.navigationController pushViewController:sessionVC animated:YES];
|
||||
CATransition *transition = [CATransition animation];
|
||||
transition.duration = 0.3f;
|
||||
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
|
||||
transition.type = kCATransitionPush;
|
||||
transition.subtype = kCATransitionFromRight;
|
||||
[self.mainController.view.layer addAnimation:transition forKey:nil];
|
||||
[self.mainController addChildViewController:sessionVC];
|
||||
[self.mainController.view addSubview:sessionVC.view];
|
||||
} else if(self.type == ContactUseingType_Share) {
|
||||
if (self.delegate && [self.delegate respondsToSelector:@selector(xPMineFansViewController:didSelectItem:)]) {
|
||||
[self.delegate xPMineFansViewController:self didSelectItem:fansInfoModel];
|
||||
|
@@ -20,6 +20,8 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
@property (nonatomic,assign) ContactUseingType type;
|
||||
///代理
|
||||
@property (nonatomic,weak) id<XPMineFriendViewControllerDelegate> delegate;
|
||||
/** 控制器 因为房间内聊天没有控制器去push 或者做其他的操作*/
|
||||
@property (nonatomic, weak) UIViewController * mainController;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
@@ -104,6 +104,17 @@
|
||||
if (self.delegate && [self.delegate respondsToSelector:@selector(xPMineFriendViewController:didSelectItem:)]) {
|
||||
[self.delegate xPMineFriendViewController:self didSelectItem:userInfo];
|
||||
}
|
||||
} else if(self.type == ContactUseingType_In_Room) {
|
||||
SessionViewController * sessionVC = [[SessionViewController alloc] initWithSession:[NIMSession session:[NSString stringWithFormat:@"%ld", userInfo.uid] type:NIMSessionTypeP2P]];
|
||||
sessionVC.openType = SessionListOpenTypeRoom;
|
||||
CATransition *transition = [CATransition animation];
|
||||
transition.duration = 0.3f;
|
||||
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
|
||||
transition.type = kCATransitionPush;
|
||||
transition.subtype = kCATransitionFromRight;
|
||||
[self.mainController.view.layer addAnimation:transition forKey:nil];
|
||||
[self.mainController addChildViewController:sessionVC];
|
||||
[self.mainController.view addSubview:sessionVC.view];
|
||||
} else {
|
||||
SessionViewController * sessionVC = [[SessionViewController alloc] initWithSession:[NIMSession session:[NSString stringWithFormat:@"%ld", userInfo.uid] type:NIMSessionTypeP2P]];
|
||||
sessionVC.openType = SessionListOpenTypeRoom;
|
||||
|
@@ -12,6 +12,9 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
@interface XPRoomHalfMessageView : UIView
|
||||
///私聊的用户ID
|
||||
@property (nonatomic,copy) NSString *chatUserId;
|
||||
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame controller:(UIViewController *)controller;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
@@ -10,43 +10,69 @@
|
||||
#import <Masonry/Masonry.h>
|
||||
#import "XPMacro.h"
|
||||
#import "BaseNavigationController.h"
|
||||
#import "XCCurrentVCStackManager.h"
|
||||
///View
|
||||
#import "XPMineContactViewController.h"
|
||||
|
||||
UIKIT_EXTERN NSString * kRoomChatPushViewKey;
|
||||
|
||||
@interface XPRoomHalfMessageView ()
|
||||
///点击消失的View
|
||||
@property (nonatomic,strong) UIView *dismissView;
|
||||
///消息的容器
|
||||
@property (nonatomic,strong) UIWindow *messageWindow;
|
||||
///联系人的VC
|
||||
@property (nonatomic,strong) XPMineContactViewController *contactVC;
|
||||
@property (nonatomic,weak) UIViewController *roomVC;
|
||||
@end
|
||||
|
||||
@implementation XPRoomHalfMessageView
|
||||
|
||||
- (void)dealloc {
|
||||
NSLog(@"aaaaa");
|
||||
}
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame {
|
||||
self = [super initWithFrame:frame];
|
||||
if (self) {
|
||||
self.tag = 888;
|
||||
[self initSubViews];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dismissViewTap) name:kRoomChatPushViewKey object:nil];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame controller:(UIViewController *)controller {
|
||||
self = [super initWithFrame:frame];
|
||||
if (self) {
|
||||
self.tag = 888;
|
||||
self.roomVC = controller;
|
||||
[self initSubViews];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dismissViewTap) name:kRoomChatPushViewKey object:nil];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma mark - Private Method
|
||||
- (void)initSubViews {
|
||||
XPMineContactViewController * vc=[XPMineContactViewController new];
|
||||
CAShapeLayer * layer = [CAShapeLayer layer];
|
||||
UIBezierPath * path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, KScreenWidth, kHalfScreenHeight) byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(12, 12)];
|
||||
layer.path = path.CGPath;
|
||||
vc.view.layer.masksToBounds = YES;
|
||||
vc.view.layer.mask = layer;;
|
||||
vc.view.frame = CGRectMake(0, KScreenHeight - kHalfScreenHeight, KScreenWidth, kHalfScreenHeight);
|
||||
self.contactVC = vc;
|
||||
|
||||
|
||||
[self addSubview:self.dismissView];
|
||||
[self addSubview:self.messageWindow];
|
||||
[self addSubview:self.contactVC.view];
|
||||
[self.roomVC addChildViewController:vc];
|
||||
}
|
||||
|
||||
#pragma mark - Event Response
|
||||
- (void)dismissViewTap {
|
||||
[self removeFromSuperview];
|
||||
self.messageWindow.rootViewController = nil;
|
||||
self.messageWindow.windowLevel = -1;
|
||||
self.messageWindow = nil;
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:@"roomMessageTabelViewStopScroll" object:nil];
|
||||
self.contactVC = nil;
|
||||
// [[NSNotificationCenter defaultCenter] postNotificationName:@"roomMessageTabelViewStopScroll" object:nil];
|
||||
}
|
||||
|
||||
#pragma mark - Getters And Setters
|
||||
@@ -55,6 +81,8 @@
|
||||
self.contactVC.chatUserId = chatUserId;
|
||||
}
|
||||
|
||||
|
||||
|
||||
- (UIView *)dismissView {
|
||||
if (!_dismissView) {
|
||||
_dismissView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight - kHalfScreenHeight)];
|
||||
@@ -65,26 +93,4 @@
|
||||
}
|
||||
return _dismissView;
|
||||
}
|
||||
|
||||
- (UIWindow *)messageWindow {
|
||||
if (!_messageWindow) {
|
||||
//创建测试导航器以及vc
|
||||
XPMineContactViewController * vc=[XPMineContactViewController new];
|
||||
self.contactVC = vc;
|
||||
BaseNavigationController * nav = [[BaseNavigationController alloc] initWithRootViewController:vc];
|
||||
//创建window,并将window的坐标设置在屏幕底部,设置windowLevel防止获取默认window失败
|
||||
UIWindow *testWindow = [[UIWindow alloc] initWithFrame:CGRectMake(0, KScreenHeight - kHalfScreenHeight, KScreenWidth, kHalfScreenHeight)];
|
||||
CAShapeLayer * layer = [CAShapeLayer layer];
|
||||
UIBezierPath * path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, KScreenWidth, kHalfScreenHeight) byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(12, 12)];
|
||||
layer.path = path.CGPath;
|
||||
testWindow.layer.masksToBounds = YES;
|
||||
testWindow.layer.mask = layer;;
|
||||
testWindow.windowLevel = UIWindowLevelAlert;
|
||||
testWindow.rootViewController = nav;
|
||||
testWindow.hidden = NO;
|
||||
testWindow.tag = 1000;
|
||||
_messageWindow = testWindow;
|
||||
}
|
||||
return _messageWindow;
|
||||
}
|
||||
@end
|
||||
|
@@ -354,8 +354,9 @@
|
||||
}
|
||||
|
||||
- (void)xPRoomNewUserGreetView:(XPRoomNewUserGreetView *)view didClickCheckout:(UIButton *)sender {
|
||||
XPRoomHalfMessageView *halfMessageView = [[XPRoomHalfMessageView alloc] initWithFrame:CGRectMake(0, KScreenHeight, KScreenWidth, KScreenHeight)];
|
||||
[[UIApplication sharedApplication].delegate.window addSubview:halfMessageView];
|
||||
UIViewController * controller = (UIViewController *)self.delegate;
|
||||
XPRoomHalfMessageView *halfMessageView = [[XPRoomHalfMessageView alloc] initWithFrame:CGRectMake(0, KScreenHeight, KScreenWidth, KScreenHeight) controller:controller];
|
||||
[controller.view addSubview:halfMessageView];
|
||||
[UIView animateWithDuration:.35 animations:^{
|
||||
CGRect rect = halfMessageView.frame;
|
||||
rect.origin.y = 0;
|
||||
|
@@ -130,8 +130,9 @@
|
||||
break;
|
||||
case XPRoomMenuItemType_Message:
|
||||
{
|
||||
XPRoomHalfMessageView *halfMessageView = [[XPRoomHalfMessageView alloc] initWithFrame:CGRectMake(0, KScreenHeight, KScreenWidth, KScreenHeight)];
|
||||
[[UIApplication sharedApplication].delegate.window addSubview:halfMessageView];
|
||||
UIViewController * controller = (UIViewController *)self.delegate;
|
||||
XPRoomHalfMessageView *halfMessageView = [[XPRoomHalfMessageView alloc] initWithFrame:CGRectMake(0, KScreenHeight, KScreenWidth, KScreenHeight) controller:controller];
|
||||
[controller.view addSubview:halfMessageView];
|
||||
[UIView animateWithDuration:.35 animations:^{
|
||||
CGRect rect = halfMessageView.frame;
|
||||
rect.origin.y = 0;
|
||||
@@ -419,9 +420,10 @@
|
||||
|
||||
#pragma mark - XPRoomMessageBubbleViewDelegate
|
||||
- (void)xPRoomMessageBubbleView:(XPRoomMessageBubbleView *)view didSelectSession:(NIMRecentSession *)session {
|
||||
XPRoomHalfMessageView *halfMessageView = [[XPRoomHalfMessageView alloc] initWithFrame:CGRectMake(0, KScreenHeight, KScreenWidth, KScreenHeight)];
|
||||
UIViewController * controller = (UIViewController *)self.delegate;
|
||||
XPRoomHalfMessageView *halfMessageView = [[XPRoomHalfMessageView alloc] initWithFrame:CGRectMake(0, KScreenHeight, KScreenWidth, KScreenHeight) controller:controller];
|
||||
halfMessageView.chatUserId = session.session.sessionId;
|
||||
[[UIApplication sharedApplication].delegate.window addSubview:halfMessageView];
|
||||
[controller.view addSubview:halfMessageView];
|
||||
[UIView animateWithDuration:.35 animations:^{
|
||||
CGRect rect = halfMessageView.frame;
|
||||
rect.origin.y = 0;
|
||||
|
@@ -739,9 +739,10 @@
|
||||
case UserCardItemType_Chat:
|
||||
{
|
||||
[self dismissViewControllerAnimated:YES completion:^{
|
||||
XPRoomHalfMessageView *halfMessageView = [[XPRoomHalfMessageView alloc] initWithFrame:CGRectMake(0, KScreenHeight, KScreenWidth, KScreenHeight)];
|
||||
UIViewController * controller = (UIViewController *)self.cardInfo.delegate;
|
||||
XPRoomHalfMessageView *halfMessageView = [[XPRoomHalfMessageView alloc] initWithFrame:CGRectMake(0, KScreenHeight, KScreenWidth, KScreenHeight) controller:controller];
|
||||
halfMessageView.chatUserId = self.cardInfo.uid;
|
||||
[[UIApplication sharedApplication].delegate.window addSubview:halfMessageView];
|
||||
[controller.view addSubview:halfMessageView];
|
||||
[UIView animateWithDuration:.35 animations:^{
|
||||
CGRect rect = halfMessageView.frame;
|
||||
rect.origin.y = 0;
|
||||
|
Reference in New Issue
Block a user