在 iOS 上,视图是否可能始终漂浮在所有其他视图之上。我问这个是因为我想要实现的是一个漂浮在 ViewController 之上的视图,然后一个模态视图控制器滑入,同时该特定视图仍然漂浮在该模态视图控制器上(希望你明白我想说的)。
有。您可以将您的视图添加到主视图中window
必要时将其放在前面。
在下面的代码中假设_viewConroller
and _anotherView
是 appDelegate 的强大属性 - 配置当然可以不同。
此代码将在屏幕左上角添加蓝色小方块。
- (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;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)