iOS如何判断,当前展示的窗口或者控制器?

iOS如何判断当前展示窗口(即具体在那个视图控制器VC)?

- (UIViewController *)activityViewController

{

UIViewController* activityViewController = nil;

UIWindow *window = [[UIApplication sharedApplication] keyWindow];

if(window.windowLevel != UIWindowLevelNormal)

{

NSArray *windows = [[UIApplication sharedApplication] windows];

for(UIWindow *tmpWin in windows)

{

if(tmpWin.windowLevel == UIWindowLevelNormal)

{

window = tmpWin;

break;

}

}

}

NSArray *viewsArray = [window subviews];

if([viewsArray count] > 0)

{

UIView *frontView = [viewsArray objectAtIndex:0];

id nextResponder = [frontView nextResponder];

if([nextResponder isKindOfClass:[UIViewController class]])

{

activityViewController = nextResponder;

}

else

{

activityViewController = window.rootViewController;

}

}

return activityViewController;

}


判断当前展示的是否我指定的某个控制器?

当前窗口可以为当前打开的任意界面,此时我要判断是否打开的界面是我的烟雾探测器执行界面。


iOS如何判断,当前展示的窗口或者控制器?_第1张图片
图:烟雾探测器界面

UIViewController *vc = [self activityViewController];

ANSSmogAlarmViewController *smogVC =[[ANSSmogAlarmViewController alloc] init];

if ([vc isMemberOfClass:[smogVC class]])

{

NSLog(@"点击了确定健");

dispatch_async(dispatch_get_main_queue(), ^{

smogVC.smogAlarmStateImageView.image = [ImageCenter imageWithName:@"device_smog_alarm_image_highlight@2x"];

});

}

你可能感兴趣的:(iOS如何判断,当前展示的窗口或者控制器?)