KLCPopup是一个简单且灵活的iOS类,用于将任何自定义视图作为弹出窗口显示。它包含各种选项,用于控制弹出窗口的外观和行为。
KLCPopup/KLCPopup
文件夹拖到您的项目中。"KLCPopup.h"
。(请参阅/KLCPopupExample
中的示例Xcode项目)
使用默认动画和行为创建一个用于显示UIView的弹出窗口(类似于UIAlertView)
+ (KLCPopup*)popupWithContentView:(UIView*)contentView;
或者,创建一个具有自定义动画和行为的弹出窗口。也可以通过弹出实例的属性访问自定义化
+ (KLCPopup*)popupWithContentView:(UIView*)contentView
showType:(KLCPopupShowType)showType
dismissType:(KLCPopupDismissType)dismissType
maskType:(KLCPopupMaskType)maskType
dismissOnBackgroundTouch:(BOOL)shouldDismissOnBackgroundTouch
dismissOnContentTouch:(BOOL)shouldDismissOnContentTouch;
注意:您可以在创建弹出窗口时传递nil
给contentView
,但必须在显示它之前将一个contentView
分配给弹出窗口!
另外,在显示之前,您必须给您的contentView
一个大小(通过设置其框架),或者它必须通过自动布局自动调整大小。
在屏幕中间显示弹出窗口。
- (void)show;
有两种方法可以控制弹出窗口显示的位置:
相对布局预设(请参阅KLCPopup.h
以获取选项)。
- (void)showWithLayout:(KLCPopupLayout)layout;
相对于视图坐标系统的显式中心点。
- (void)showAtCenter:(CGPoint)center inView:(UIView*)view;
如果要让您的弹出窗口自动消失(类似于Android中的toast),您可以设置显式的duration
- (void)showWithDuration:(NSTimeInterval)duration;
有几种方法可以消失弹出窗口:
如果您有一个弹出实例的引用,您可以向它发送此消息。如果animated
,则它将使用在dismissType
中指定的动画。否则,它将直接消失
- (void)dismiss:(BOOL)animated;
如果您丢失了对弹出窗口的引用或您想要确保没有弹出窗口在显示,则此类方法会关闭您的应用程序中的任何和所有弹出窗口
+ (void)dismissAllPopups;
此外,您还可以从UIView(KLCPopup)
调用此分类方法,在您的contentView
或其任何子视图中,以关闭其父弹出窗口
- (void)dismissPresentingPopup; // UIView category
用于显示您的弹出窗口的动画
@property (nonatomic, assign) KLCPopupShowType showType;
用于消失您的弹出窗口的动画
@property (nonatomic, assign) KLCPopupDismissType dismissType;
遮罩防止触摸背景传递到底下的视图
@property (nonatomic, assign) KLCPopupMaskType maskType;
触摸背景时,弹出窗口将自动消失
@property (nonatomic, assign) BOOL shouldDismissOnBackgroundTouch;
触摸内容视图时,弹出窗口将自动消失
@property (nonatomic, assign) BOOL shouldDismissOnContentTouch;
覆盖模糊背景遮罩的alpha值
@property (nonatomic, assign) CGFloat dimmedMaskAlpha;
使用这些块来同步其他操作与弹出事件
@property (nonatomic, copy) void (^didFinishShowingCompletion)();
@property (nonatomic, copy) void (^willStartDismissingCompletion)();
@property (nonatomic, copy) void (^didFinishDismissingCompletion)();
UIView* contentView = [[UIView alloc] init];
contentView.backgroundColor = [UIColor orangeColor];
contentView.frame = CGRectMake(0.0, 0.0, 100.0, 100.0);
KLCPopup* popup = [KLCPopup popupWithContentView:contentView];
[popup show];
KLCPopup
默认支持纵向和横向。
KLCPopup
需要iOS 7。尚未在iOS 8上测试。
KLCPopup
支持iPhone和iPad。
KLCPopup
需要ARC。
KLCPopup 由Jeff Mascia和Kullect团队创建,在Shout Photo Messenger应用中使用。KLCPopup的一些方面受到了Sam Vermette的SVProgressHUD的启发。