简体   繁体   English

iOS:如何在主视图顶部显示小视图?

[英]iOS: How to display a small view on top of main view?

I'm new here, don't be very hard on me :) 我是新来的,不要对我很努力:)

Learning iOS development and trying to display a small view to enter some data to my app, which is using storyboards. 学习iOS开发并尝试显示一个小视图,将一些数据输入我的应用程序,即使用故事板。

I tried adding it as subview but I can't move it from the top-left corner or make the background to fade. 我尝试将其添加为子视图,但我无法从左上角移动它或使背景淡出。 Any advice on how to do this? 关于如何做到这一点的任何建议?

Forgot to mention that this is for iPhone. 忘记提到这是为iPhone。

Thanks 谢谢

Based on your comment it seems that you don't have a clear understanding of the difference between UIView and UIViewController. 根据您的评论,您似乎没有清楚地了解UIView和UIViewController之间的区别。

Think of a UIViewController as your screen. 将UIViewController视为您的屏幕。 Your screen might be showing many different views at once, but they are all part of the UIViewController's view. 您的屏幕可能同时显示许多不同的视图,但它们都是UIViewController视图的一部分。

Rather then present a new UIViewController (ie screen), you want to do something like this: 而不是呈现一个新的UIViewController(即屏幕),你想做这样的事情:

//Use a XIB for this, not a storyboard
UIView *newView = [[[NSBundle mainBundle] loadNibNamed:@"addData" owner:self options:nil] lastObject];
[self.view addSubview:newView];

I suggest reading these two guides from Apple until you understand the difference between a UIView and a UIViewController: 我建议你阅读Apple的这两个指南,直到你理解了UIView和UIViewController之间的区别:

View Programming Guide 查看编程指南

View Controller Programming Guide View Controller编程指南

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM