重置完 rootviewcontroller, BBGestureBaseView 要怎么添加
Opened this issue · 13 comments
重置完rootViewController,是什么意思?
换个了 根控制器?新的根控制器也是这个吗? 有继承这个吗?是 模态出来 一个 新的根控制器?还是?
不是模态 是 UIApplication.shared.keyWindow?.rootViewController = rootViewController;
因为 gestureBaseView 不是要添加到Windows上面吗? 我重新添加无效; 不知道咋解决;
不好意思,我不太清楚您具体是在哪里,怎么样替换rootViewController的,有具体的需求吗?引导图?广告图?或者您能提供下demo,供我参考下,我才能更好的找到问题,因为当初没有这个需求,可能没有涉及到这个问题,望见谅!
如下,比如在商品详情发出通知,appdelegate收到通知:
-(void)userLoginStatusNotification:(NSNotification *)noti{
//使用object处理消息
NSString *info = [noti object];
DLog(@"接收 object传递的消息:%@",info);
NSString *token = [kUserDefaults objectForKey:kUserToken];
if (kStringIsEmpty(token)) {
//未登录
UMPLoginViewController *myView = [MAIN_STORY_BOARD(@"UMPLoginStoryboard") instantiateViewControllerWithIdentifier:@"UMPLoginViewController"];
myView.title = @"登录";
UMPBaseNavigationController *navi = [[UMPBaseNavigationController alloc] initWithRootViewController:myView];
self.window.rootViewController = navi;
}else{
//已登录
UMPTabBarViewController *tarBarController = [[UMPTabBarViewController alloc] init];
self.window.rootViewController = tarBarController ;
}
self.gestureBaseView = [[BBGestureBaseView alloc] initWithFrame:CGRectMake(0, 0, self.window.frame.size.width, self.window.frame.size.height)];
[self.window insertSubview:self.gestureBaseView atIndex:0];
self.gestureBaseView.hidden = YES;
// for (UIView *view in self.window.subviews) {
// NSLog(@"再次---------%@",view);
// if ([view isKindOfClass:[BBGestureBaseView class]]) {
// if ([self.window.subviews indexOfObject:view] != 0) {
// BBGestureBaseView *bbview = (BBGestureBaseView *)view;
// //表明该View已被废弃,需要及时删除
// bbview.isDiscarded = YES;
// [bbview removeFromSuperview];
// }
// }
// }
// for (UIView *view in self.window.subviews) {
// NSLog(@"删除之后---------%@",view);
// }
}
我注释的代码如果不打开,那么BBGestureBaseView会重复添加,打开后删除这个View是成功的,没有报错,但是需要在BBGestureBaseView中添加一个属性值,表明该View已经被废弃。
@implementation BBGestureBaseView
-
(id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.isDiscarded = NO;
self.arrayImage = [NSMutableArray array];
self.backgroundColor = [UIColor blackColor];
self.imgView = [[UIImageView alloc] initWithFrame:self.bounds];
self.maskView = [[UIView alloc] initWithFrame:self.bounds];
self.maskView.backgroundColor = [UIColor colorWithHue:0 saturation:0 brightness:0 alpha:BBMaskingAlpha];
[self addSubview: self.imgView];
[self addSubview: self.maskView];
[[AppDelegate shareAppDelegate].window.rootViewController.view addObserver:self forKeyPath:@"transform" options:NSKeyValueObservingOptionNew context:bbListenTabbarViewMove];
}
return self;
} -
(void)dealloc{
if (!self.isDiscarded) {
[[AppDelegate shareAppDelegate].window.rootViewController.view removeObserver:self forKeyPath:@"transform" context:bbListenTabbarViewMove];
}NSLog(@"%s",FUNCTION);
}
你好,我也遇到了同样的问题,比如app多tab的情况,切换rootViewController的时候, gestureview重新添加就没什么效果:
//1.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = [[YTabBarController alloc] init];
self.gestureBaseView = [[BBGestureBaseView alloc] initWithFrame:CGRectMake(0, 0, self.window.frame.size.width, self.window.frame.size.height)];
[self.window insertSubview:self.gestureBaseView atIndex:0];
self.gestureBaseView.hidden = YES;
[self.window makeKeyAndVisible];
return YES;
}
//2. - (void)testClick {
AppDelegate *appDelegate = [AppDelegate shareAppDelegate];
Y2TabBarController *cTab = [[Y2TabBarController alloc] init];
appDelegate.window.rootViewController = cTab;
self.gestureBaseView = [[BBGestureBaseView alloc] initWithFrame:CGRectMake(0, 0, appDelegate.window.frame.size.width, appDelegate.window.frame.size.height)];
[appDelegate.window insertSubview:self.gestureBaseView atIndex:0];
self.gestureBaseView.hidden = YES;
}
这种情况怎么办呢?
已收到,已解决,这边正在完善,马上迭代,稍安勿躁
你好,我也遇到了同样的问题,比如app多tab的情况,切换rootViewController的时候, gestureview重新添加就没什么效果:
//1.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = [[YTabBarController alloc] init];
self.gestureBaseView = [[BBGestureBaseView alloc] initWithFrame:CGRectMake(0, 0, self.window.frame.size.width, self.window.frame.size.height)];
[self.window insertSubview:self.gestureBaseView atIndex:0];
self.gestureBaseView.hidden = YES;
[self.window makeKeyAndVisible];
return YES;
}
//2.- (void)testClick {
AppDelegate *appDelegate = [AppDelegate shareAppDelegate];
Y2TabBarController *cTab = [[Y2TabBarController alloc] init];
appDelegate.window.rootViewController = cTab;
self.gestureBaseView = [[BBGestureBaseView alloc] initWithFrame:CGRectMake(0, 0, appDelegate.window.frame.size.width, appDelegate.window.frame.size.height)];
[appDelegate.window insertSubview:self.gestureBaseView atIndex:0];
self.gestureBaseView.hidden = YES;
}
这种情况怎么办呢?
我已经重新上传了demo,望参考
收到