GVKun编程网logo

iOS 获取当前正在显示的ViewController(正在获取io地址)

5

对于想了解iOS获取当前正在显示的ViewController的读者,本文将提供新的信息,我们将详细介绍正在获取io地址,并且为您提供关于Appdelegate跳转其他页面获取当前屏幕显示的viewc

对于想了解iOS 获取当前正在显示的ViewController的读者,本文将提供新的信息,我们将详细介绍正在获取io地址,并且为您提供关于Appdelegate 跳转其他页面 获取当前屏幕显示的 viewcontroller 获取当前屏幕中 present 出来的 viewcontroller 获取当前导航控制器、iOS 7中的ViewView在ViewController和NavigationBar中模糊效果、iOS presentViewController 与 pushViewController 中的注意点、iOS presentViewController 推出半屏幕透明 UIViewController的有价值信息。

本文目录一览:

iOS 获取当前正在显示的ViewController(正在获取io地址)

iOS 获取当前正在显示的ViewController(正在获取io地址)

1.我们在非视图类中想要随时展示一个view时,需要将被展示的view加到当前view的子视图,或用当前view presentViewController,或pushViewContrller,这些操作都需要获取当前正在显示的ViewController。

//获取当前屏幕显示的viewcontroller - (UIViewController *)getCurrentVC { UIViewController *result = 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; } } } UIView *frontView = [[window subviews] objectAtIndex:0]; id nextResponder = [frontView nextResponder]; if ([nextResponder isKindOfClass:[UIViewController class]]) result = nextResponder; else result = window.rootViewController; return result; }

 

2.获取当前屏幕中present出来的viewcontroller。

- (UIViewController *)getPresentedViewController { UIViewController *appRootVC = [UIApplication sharedApplication].keyWindow.rootViewController; UIViewController *topVC = appRootVC; if (topVC.presentedViewController) { topVC = topVC.presentedViewController; } return topVC; }

Appdelegate 跳转其他页面 获取当前屏幕显示的 viewcontroller 获取当前屏幕中 present 出来的 viewcontroller 获取当前导航控制器

Appdelegate 跳转其他页面 获取当前屏幕显示的 viewcontroller 获取当前屏幕中 present 出来的 viewcontroller 获取当前导航控制器

Appdelegate 跳转其他页面

UITabBarController *tab = (UITabBarController *)_window.rootViewController;    

UINavigationController *nav = tab.viewControllers[tab.selectedIndex];    

MessageViewController *vc = [[MessageViewController alloc] init];    需要跳转的页面

vc.hidesBottomBarWhenPushed = YES;    

[nav pushViewController:vc animated:YES]; 

 

 

// 获取当前屏幕显示的 viewcontroller

- (UIViewController *)getCurrentVC{

    UIWindow *window = [[UIApplication sharedApplication].windows firstObject];

    if (!window) {

        return nil;

    }

    UIView *tempView;

    for (UIView *subview in window.subviews) {

        if ([[subview.classForCoder description] isEqualToString:@"UILayoutContainerView"]) {

            tempView = subview;

            break;

        }

    }

    if (!tempView) {

        tempView = [window.subviews lastObject];

    }

    

    id nextResponder = [tempView nextResponder];

    while (![nextResponder isKindOfClass:[UIViewController class]] || [nextResponder isKindOfClass:[UINavigationController class]] || [nextResponder isKindOfClass:[UITabBarController class]]) {

        tempView =  [tempView.subviews firstObject];

        

        if (!tempView) {

            return nil;

        }

        nextResponder = [tempView nextResponder];

    }

    return  (UIViewController *)nextResponder;

}

 

 

 

// 获取当前屏幕中 present 出来的 viewcontroller。

- (UIViewController *)getPresentedViewController

{

    UIViewController *appRootVC = [UIApplication sharedApplication].keyWindow.rootViewController;

    UIViewController *topVC = appRootVC;

    if (topVC.presentedViewController) {

        topVC = topVC.presentedViewController;

    }

    return topVC;

}

 

 

// 获取当前导航控制器

- (BaseNavigationController *)getNavController{

    BaseTableBarControllerView *tabVC = (BaseTableBarControllerView *)self.window.rootViewController;

    tabVC.selectedIndex = 2;

    BaseNavigationController *pushClassStance = (BaseNavigationController *)tabVC.selectedViewController;

    return pushClassStance;

}

iOS 7中的ViewView在ViewController和NavigationBar中模糊效果

iOS 7中的ViewView在ViewController和NavigationBar中模糊效果

我在应用程序中使用TableViewController在故事板中构建了TableView.当您这样做时,当您向下滚动您的列表时,您会有非常酷的效果:移动导航栏后面的单元格变得模糊.

一段时间后,我不得不从TableViewController移动到具有TableView的ViewController(我必须在表的底部添加其他视图).

为了避免导航栏隐藏第一个单元格(在其上),我添加了顶部和底部布局指南以及视图左右边缘的约束.

这样做很好,但是我失去了很酷的模糊滚动效果:细胞似乎正在消失,然后在导航栏后面.

我已经看到解决方法与人没有使用约束和魔术数字在界面构建器.我不能这样做,首先是因为我不喜欢,第二是因为我必须要iOS 6兼容.

我错过了什么能够从模糊的导航栏效果再次受益?

解决方法

您必须手动调整表视图的contentInset,并确保表视图帧原点为0,0.
以这种方式,表格视图将在导航栏的下方,但内容和滚动视图边缘之间会有一些余量(内容被向下移动).

我建议您使用view controller的topLayoutGuide属性来设置正确的contentInsets,而不是硬编码64(状态栏导航栏).
还有bottomLayoutGuide,在UITapBars的情况下你应该使用它.

这里是一些示例代码(viewDidLoad应该是罚款):

// Set edge insets
CGFloat topLayoutGuide = self.topLayoutGuide.length;
tableView.contentInset = UIEdgeInsetsMake(topLayoutGuide,0);

顺便说一下,UIViewController的这个属性可能会帮助你(你不需要改变它们的默认值,但是我不知道你的视图层次结构是什么):

> automaticallyAdjustsScrollViewInsets> edgesForExtendedLayout> extendedLayoutIncludesOpaqueBars

iOS presentViewController 与 pushViewController 中的注意点

iOS presentViewController 与 pushViewController 中的注意点

从数据到大模型应用,11 月 25 日,杭州源创会,共享开发小技巧

要做 push,前提要存在 navigationController。 present 进来的页面如果有 push 操作,该页面必须带有 NavigationController。

iOS presentViewController 推出半屏幕透明 UIViewController

iOS presentViewController 推出半屏幕透明 UIViewController

iOS presentViewController 推出半屏幕透明 UIViewController

不废话,直接上代码

1.父页面打开方式

/**
 *  页面打开配置
 *
 *  @param sender <#sender description#>
 */
- (IBAction)shwoViewAction:(id)sender {
    
    TTViewController *tView = [[TTViewController alloc] init];
    //设置模式展示风格
    [tView setModalPresentationStyle:UIModalPresentationOverCurrentContext];
    //必要配置
    self.modalPresentationStyle = UIModalPresentationCurrentContext;
    self.providesPresentationContextTransitionStyle = YES;
    self.definesPresentationContext = YES;
    [self presentViewController:tView animated:YES completion:nil];
}

 2.子页面重写viewWillLayoutSubviews,设置位置宽高

#define DeviceHeight [[UIScreen mainScreen] bounds].size.height
#define DeviceWidth [[UIScreen mainScreen] bounds].size.width

/**
 *  设置位置宽高
 */
- (void)viewWillLayoutSubviews {
  
    self.view.frame = CGRectMake(self.view.frame.origin.x, DeviceHeight / 2, DeviceWidth, DeviceHeight / 2);
    //self.view.backgroundColor = [UIColor clearColor];
    //self.view.backgroundColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:0.868f];
}

 打完收工。

我们今天的关于iOS 获取当前正在显示的ViewController正在获取io地址的分享就到这里,谢谢您的阅读,如果想了解更多关于Appdelegate 跳转其他页面 获取当前屏幕显示的 viewcontroller 获取当前屏幕中 present 出来的 viewcontroller 获取当前导航控制器、iOS 7中的ViewView在ViewController和NavigationBar中模糊效果、iOS presentViewController 与 pushViewController 中的注意点、iOS presentViewController 推出半屏幕透明 UIViewController的相关信息,可以在本站进行搜索。

本文标签: