前语:很多时候需要用到一个小弹窗进行信息的中心展现,或者在底部需要弹出一个弹窗进行二次承认,在寻觅过程中发现一个第三方库KLCPopup,运用起来非常方便,能够自定义弹窗视图,能够在屏幕的不同方位、不同方向、不同动效的方法进行弹出和消失,这里简略说一说运用方法吧。

github原地址KLCPopup

引入Podfile
pod 'KLCPopup'
引入项目

在终端中cd到项目目录下,进行pod install将KLCPopup引入项目

创立Popup
/// 默认创立Popup方法
+ (KLCPopup*)popupWithContentView:(UIView*)contentView;
/// 创立自定义Popup方法
/// - Parameters:
///   - contentView: 弹窗View
///   - showType: 展现方法
///   - dismissType: 消失方法
///   - maskType: 弹窗背后蒙层款式
///   - shouldDismissOnBackgroundTouch: 点击布景蒙层弹窗是否消失
///   - shouldDismissOnContentTouch: 点击弹窗视图弹窗是否消失
+ (KLCPopup*)popupWithContentView:(UIView*)contentView
						 showType:(KLCPopupShowType)showType
					  dismissType:(KLCPopupDismissType)dismissType
						 maskType:(KLCPopupMaskType)maskType
		 dismissOnBackgroundTouch:(BOOL)shouldDismissOnBackgroundTouch
			dismissOnContentTouch:(BOOL)shouldDismissOnContentTouch;

建议运用自定义Popup创立方法,这样能够更加方便的创立出满意需求的弹窗,包括展现、消失方法以及交互方法等需求。

设置Popup弹窗展现(方位、时刻)
/// 弹窗呈现(假如没有设置Layout则展现在屏幕中心)
- (void)show {
  [self showWithLayout:KLCPopupLayoutCenter];
}
/// 设置弹窗Layout
- (void)showWithLayout:(KLCPopupLayout)layout {
  [self showWithLayout:layout duration:0.0];
}
/// 设置弹窗展现时刻
- (void)showWithDuration:(NSTimeInterval)duration {
  [self showWithLayout:KLCPopupLayoutCenter duration:duration];
}
/// 设置弹窗Layout和展现时刻
- (void)showWithLayout:(KLCPopupLayout)layout duration:(NSTimeInterval)duration {
  NSDictionary* parameters = @{@"layout" : [NSValue valueWithKLCPopupLayout:layout],
                               @"duration" : @(duration)};
  [self showWithParameters:parameters];
}
/// 设置弹窗的中心点,在view视图上的方位
- (void)showAtCenter:(CGPoint)center inView:(UIView*)view {
  [self showAtCenter:center inView:view withDuration:0.0];
}
/// 设置弹窗的中心点,在view视图上的方位和展现时刻
- (void)showAtCenter:(CGPoint)center inView:(UIView *)view withDuration:(NSTimeInterval)duration {
  NSMutableDictionary* parameters = [NSMutableDictionary dictionary];
  [parameters setValue:[NSValue valueWithCGPoint:center] forKey:@"center"];
  [parameters setValue:@(duration) forKey:@"duration"];
  [parameters setValue:view forKey:@"view"];
  [self showWithParameters:[NSDictionary dictionaryWithDictionary:parameters]];
}

建议运用showWithLayout方法来修正弹窗展现方位

Popup弹窗属性
KLCPopupShowType:展现属性
// KLCPopupShowType: Controls how the popup will be presented.
typedef NS_ENUM(NSInteger, KLCPopupShowType) {
  KLCPopupShowTypeNone = 0, /// 无动画
  KLCPopupShowTypeFadeIn, /// 褪色动画
  KLCPopupShowTypeGrowIn, /// 扩大动画
  KLCPopupShowTypeShrinkIn, /// 缩小动画
  KLCPopupShowTypeSlideInFromTop, /// 从顶部滑润进入
  KLCPopupShowTypeSlideInFromBottom, /// 从底部滑润进入
  KLCPopupShowTypeSlideInFromLeft, /// 从左边滑润进入
  KLCPopupShowTypeSlideInFromRight, /// 从右边滑润进入
  KLCPopupShowTypeBounceIn, /// 从中心弹入
  KLCPopupShowTypeBounceInFromTop, /// 从上面弹入
  KLCPopupShowTypeBounceInFromBottom, /// 从底面弹入
  KLCPopupShowTypeBounceInFromLeft, /// 从左边弹入
  KLCPopupShowTypeBounceInFromRight, /// 从右边弹入
};
KLCPopupShowType:消失属性
// KLCPopupDismissType: Controls how the popup will be dismissed.
typedef NS_ENUM(NSInteger, KLCPopupDismissType) {
  KLCPopupDismissTypeNone = 0,
  KLCPopupDismissTypeFadeOut,
  KLCPopupDismissTypeGrowOut,
  KLCPopupDismissTypeShrinkOut,
  KLCPopupDismissTypeSlideOutToTop,
  KLCPopupDismissTypeSlideOutToBottom,
  KLCPopupDismissTypeSlideOutToLeft,
  KLCPopupDismissTypeSlideOutToRight,
  KLCPopupDismissTypeBounceOut,
  KLCPopupDismissTypeBounceOutToTop,
  KLCPopupDismissTypeBounceOutToBottom,
  KLCPopupDismissTypeBounceOutToLeft,
  KLCPopupDismissTypeBounceOutToRight,
};
KLCPopupMaskType:弹窗布景类型
// KLCPopupMaskType
typedef NS_ENUM(NSInteger, KLCPopupMaskType) {
	KLCPopupMaskTypeNone = 0, // Allow interaction with underlying views.
	KLCPopupMaskTypeClear, // Don't allow interaction with underlying views.
	KLCPopupMaskTypeDimmed, // Don't allow interaction with underlying views, dim background.
};
KLCPopupHorizontalLayout: 横向方位
// KLCPopupHorizontalLayout: Controls where the popup will come to rest horizontally.
typedef NS_ENUM(NSInteger, KLCPopupHorizontalLayout) {
  KLCPopupHorizontalLayoutCustom = 0,
  KLCPopupHorizontalLayoutLeft,
  KLCPopupHorizontalLayoutLeftOfCenter,
  KLCPopupHorizontalLayoutCenter,
  KLCPopupHorizontalLayoutRightOfCenter,
  KLCPopupHorizontalLayoutRight,
};
KLCPopupVerticalLayout: 纵向方位
// KLCPopupVerticalLayout: Controls where the popup will come to rest vertically.
typedef NS_ENUM(NSInteger, KLCPopupVerticalLayout) {
  KLCPopupVerticalLayoutCustom = 0,
  KLCPopupVerticalLayoutTop,
  KLCPopupVerticalLayoutAboveCenter,
  KLCPopupVerticalLayoutCenter,
  KLCPopupVerticalLayoutBelowCenter,
  KLCPopupVerticalLayoutBottom,
};

Popup运用实例

- (void)clickAlertAction {
CommonAlertView *alertView = [[CommonAlertView alloc] initWithFrame:CGRectMake(0, 0, Common.screenWidth, ([@130 fit] + Common.safeAreaBottom)) withContent:@"承认支付订单?"];
KLCPopup *popup = [KLCPopup popupWithContentView:alertView showType:KLCPopupShowTypeSlideInFromBottom dismissType:KLCPopupDismissTypeSlideOutToBottom maskType:KLCPopupMaskTypeDimmed dismissOnBackgroundTouch:YES dismissOnContentTouch:NO];
[popup showWithLayout:KLCPopupLayoutMake(KLCPopupHorizontalLayoutCenter, KLCPopupVerticalLayoutBottom)];
/// 点击撤销按钮
alertView.cancelButtonAction = ^{
	///	弹窗消失
    [popup dismiss:YES];
};
/// 点击承认按钮
alertView.confirmButtonAction = ^{
	///	弹窗消失
    [popup dismiss:YES];
    /// 履行自定义操作
    /// xxxx
};
[popup show];
}

动画展现

「OC」KLCPopup运用概况

ps:动画第一次点击了撤销,第2次点击了确认

整理不易,望我们多多点赞收藏,希望对我们有所协助!
假如有误,请各位大佬点拨!谢谢我们!!!