查看浮动在所有ViewControllers上方 [英] View floating above all ViewControllers

查看:123
本文介绍了查看浮动在所有ViewControllers上方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iOS上是否可以将视图始终浮动在所有其他视图之上。我问这个是因为我想要实现的是一个浮动在ViewController上方的视图,然后一个模态视图控制器滑入,而该特定视图仍然漂浮在该模态视图控制器上(希望你得到我想说的话) )。

Is it possible on iOS that a view always floats above all other views. I ask this because what I would like to achieve is a view that floats above a ViewController, and then a Modal View Controller slides in, whilst that particular view is still floating over that Modal View Controller (hope you get what I am trying to say).

推荐答案

有。您可以将视图添加到主窗口,并在必要时将其显示在前面。

There is. You can add your view to the main window and bring it to front when you have to.

在以下代码中假定 _viewConroller _anotherView 是appDelegate的强大属性 - 配置当然可能不同。

In following code is presumed that _viewConroller and _anotherView are strong properties of appDelegate - configuration could of course be different.

此代码会在屏幕左上角添加小蓝色方块。

This code would add small blue square on top left corner of the screen.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    _viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    _anotherView = [[UIView alloc] initWithFrame: CGRectMake (0.0,0.0,20.0,20.0)];
    [anotherView setBackgroundColor: [UIColor blueColor]];    

    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];

    [self.window addSubView: _anotherView];
    [self.window bringSubViewToFront: _anotherView]; //not really needed here but it doesn't do any harm

    return YES;
}

这篇关于查看浮动在所有ViewControllers上方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆