CWPopup是在UIViewController上的一个类别,允许您轻松地制作弹出视图控制器。
将目录CWPopup
导入到您的项目中。它包含UIViewController的类别。
首先,导入类别。
#import "UIViewController+CWPopup.h"
您可以选择使用淡入淡出背景或模糊背景。淡入淡出背景会部分模糊背景,而模糊背景则会在背景上应用模糊效果。注意:如果使用模糊背景,则不会显示任何背景动画,因为它是放置在视图上方的静态图像。默认设置为使用淡入淡出背景。要启用模糊背景,在您的viewDidLoad
函数中添加以下代码行
self.useBlurForPopup = YES;
注意:模糊仅适用于iOS 7及以上版本。
要显示视图控制器
SamplePopupViewController *samplePopupViewController = [[SamplePopupViewController alloc] initWithNibName:@"SamplePopupViewController" bundle:nil];
[self presentPopupViewController:samplePopupViewController animated:YES completion:nil];
要关闭视图控制器
if (self.popupViewController != nil) {
[self dismissPopupViewControllerAnimated:YES completion:nil];
}
就是这样。
注意:如果将animated
设置为NO
,则不会淡出背景 - 这样,如果您想实现自己的动画和淡入淡出,可以这样做。
The MIT License (MIT)
Copyright (c) 2013 Cezary Wojcik <http://www.cezarywojcik.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.