在视图上呈现 UIView
如何在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您正在寻找的是模态视图。模态视图可以很容易地让视图接管屏幕一段时间,然后当它们被消除时,背景视图会从它停止的地方恢复,而不必担心谁在顶部或在部分模糊的视图中处理事件。
这里是苹果的文章描述它。
关键是让您的视图调用
[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];
您只需在
UIWindow
或可见的UIViewController
视图上使用addSubview:
方法即可显示UIView
,您可以稍后通过在显示的UIView
上调用removeFromSuperview
来隐藏/删除它。You can just use the
addSubview:
method on yourUIWindow
or your visibleUIViewController
's view to show theUIView
, and you can hide/remove it later by callingremoveFromSuperview
on the presentedUIView
.