在视图上呈现 UIView

发布于 2024-09-18 21:44:58 字数 153 浏览 2 评论 0原文

如何在 iOS 中创建一个自定义视图,使其显示在现有视图上方,但更小?它应该类似于 UIAlertView,但取自 .xib 文件。用户点击某个按钮后,小视图消失并出现正常视图。

如果这是可能的,我该怎么做?而且..如果这对您来说不难,请包含代码。

提前致谢!

How can I make a custom view in iOS which appears above the existing view,but smaller? It should be like UIAlertView, but taken from a .xib file. After user taps a certain button, the small view vanishes and the normal view appears.

If this is posiible, how can I do it? And.. if it's not hard for you, please, include code.

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梓梦 2024-09-25 21:44:58

我认为您正在寻找的是模态视图。模态视图可以很容易地让视图接管屏幕一段时间,然后当它们被消除时,背景视图会从它停止的地方恢复,而不必担心谁在顶部或在部分模糊的视图中处理事件。

这里是苹果的文章描述它。

关键是让您的视图调用 [selfpresentModalViewController:popupControlleranimated:YES]; 的控制器类,其中“popupController”是您想要显示的视图的视图控制器。当您准备好让它消失时,请调用 [self DismissModalViewControllerAnimated: YES];

I think what you're looking for is a modal view. Modal views make it easy to have a view take over the screen for a little while, then when they get dismissed have the background view resume where it left off without having to worry about who's on top or handling events in partially-obscured views.

Here is Apple's article describing it.

They key is to have the controller class for your view call [self presentModalViewController:popupController animated:YES]; where "popupController" is the view controller for the view you want to show up. When you're ready to make it go away, call [self dismissModalViewControllerAnimated: YES];

追星践月 2024-09-25 21:44:58

您只需在 UIWindow 或可见的 UIViewController 视图上使用 addSubview: 方法即可显示 UIView ,您可以稍后通过在显示的 UIView 上调用 removeFromSuperview 来隐藏/删除它。

You can just use the addSubview: method on your UIWindow or your visible UIViewController's view to show the UIView, and you can hide/remove it later by calling removeFromSuperview on the presented UIView.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文