Coder Social home page Coder Social logo

lstpopview's Introduction

LSTPopView iOS万能弹窗

Platform Language License CocoaPods Compatible

LSTPopView 万能弹窗,功能强大,易于拓展,性能优化和内存控制让其运行更加的流畅和稳健, LSTPopView的出现,可以让我们更专注弹窗页面的布局. 省心省力 ! 提高开发效率 !

前言

  • 考虑到笔者的精力问题,遇到问题请先查看 API、效仿Demo、阅读README、搜索 Issues。如果是BUG 或 Feature,最好是提Issue
  • 联系方式: [email protected], QQ群:1045568246, 微信:a_LSTKit
  • 开发环境: Xcode12.3, iOS13.5, iPhone XS Max~

博客地址

目录

特性

  • 提供丰富的api,高度自定义弹窗,简单入手使用
  • 支持弹出动画,消失动画,主动动画等多重动画搭配
  • 支持点击,长按,拖拽,横扫手势交互
  • 支持多弹窗管理:编队,堆叠,优先级等
  • 支持指定弹窗父类,eg: UIWindow,self.view等
  • 安全且内存占用小,弹窗内存自动回收
  • 提供生命周期api,自定义动画控制
  • 自动规避键盘,防止被键盘遮挡
  • 支持定时器,多定时器机制
  • 支持纯代码/xib页面
  • 支持横竖屏切换
  • 支持多代理机制
  • 支持二次封装,比如组件LSTHUD,LSTAlertView等

版本更新历史

安装

  • OC版本安装

    • CocoaPods安装: 在podfile文件中添加以下描述,然后 pod install 或者 pod update

      pod 'LSTPopView'
      
    • Carthage安装:(暂时未适配)

  • Swift版本安装

    • (计划开发中)
  • 手动导入集成

    • 1.拖动LSTPopView文件下5个文件到项目中
    LSTPopView.h
    LSTPopView.m
    UIView+LSTPV.h
    UIView+LSTPV.m
    LSTPopViewProtocol.h
    pod 'LSTTimer'

基本使用

  • 代码示例

    //自定义view
    LSTPopViewTVView *customView = [[LSTPopViewTVView alloc] initWithFrame:CGRectMake(0, 0, 300,400)];
    //创建弹窗PopViiew 指定父容器self.view, 不指定默认是app window
    LSTPopView *popView = [LSTPopView initWithCustomView:customView
                                              parentView:self.view
                                                popStyle:LSTPopStyleSmoothFromBottom
                                            dismissStyle:LSTDismissStyleSmoothToBottom];
    //弹窗位置: 居中 贴顶 贴左 贴底 贴右 
    popView.hemStyle = LSTHemStyleBottom;
    LSTPopViewWK(popView)
    //点击背景触发
    popView.bgClickBlock = ^{ [wk_popView dismiss]; };
    //弹窗显示
    [popView pop];
  • 调试日志

    /** 调试日志类型 */
    typedef NS_ENUM(NSInteger, LSTPopViewLogStyle) {
    LSTPopViewLogStyleNO = 0,          // 关闭调试信息(窗口和控制台日志输出)
    LSTPopViewLogStyleWindow,          // 开启左上角小窗
    LSTPopViewLogStyleConsole,         // 开启控制台日志输出
    LSTPopViewLogStyleALL              // 开启小窗和控制台日志
    };
    • 调试小窗: S表示当前已经显示的弹窗数, R表示在移除队列的弹窗, S+R是表示当前所有的弹窗数

使用注意事项

(一定用weak修饰)

  • 解析: LSTPopView对每个弹窗都有自动内存销毁机制, 外部对弹窗的强引用对打破这种自动内存销毁机制, 比如成员变量用strong修饰,否则弹窗不能自动销毁,导致内存回收不了.

  • 类成员变量使用规范:

    //成员变量用weak修饰, 不可以用strong修饰
    @property (nonatomic,weak) LSTPopView *popView;
  • 成员变量的创建

    LSTPopViewTVView *customView = [[LSTPopViewTVView alloc] initWithFrame:CGRectMake(0, 0, 300,400)];
    //弹窗实例创建
    LSTPopView *popView = [LSTPopView initWithCustomView:customView
                                                  popStyle:LSTPopStyleSmoothFromBottom
                                              dismissStyle:LSTDismissStyleSmoothToBottom];
    //这里赋值给成员变量self.popView
    self.popView = popView;
    [popView pop];
  • 错误使用:

    //直接赋值给成员变量 导致成员变量为空, 请参考以上使用规范
    self.popView = [LSTPopView initWithCustomView:customView
                                           popStyle:LSTPopStyleSmoothFromBottom
                                       dismissStyle:LSTDismissStyleSmoothToBottom];

演示效果

  • 应用市场常用的示例场景
QQ,微信,UC,微博,抖音
图片名称
拖拽移除,横扫移除
图片名称
  • 丰富的出入场动画, 拖拽, 横扫动画
弹出动画,中间,自上,自左,自下,自左
图片名称
移除动画,中间,至上,至左,至下,至左
图片名称
拖拽,横扫动画
图片名称
  • 弹窗位置
弹窗位置,中间,贴顶,贴左,贴底,贴右
图片名称
X轴,Y轴调教,宽度和高度调教
图片名称
  • 自动规避键盘遮挡,指定容器,定时器
自动规避键盘遮挡
图片名称
指定容器弹出
图片名称
弹窗计时
图片名称
  • 多弹窗管理(优先级,编队)
app启动多弹窗优先级显示
图片名称
多窗口编队使用
图片名称
  • 支持横竖屏
屏幕旋转
图片名称

作者

[email protected], QQ群:1045568246, 微信:a_LSTKit

版权

尊重劳动成果, 人人有责.

lstpopview's People

Contributors

jjq700 avatar kchtin avatar losentrad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lstpopview's Issues

第一个XPopup中创建第二个XPopup经常出现异常

我在第一个XPopup的button按钮创建并显示第二个XPopup,但是经常出现崩溃。在“LSTPopView.m“文件的511行处,代码是“id obj = popViewArr[popViewArr.count-2];”。xcode的bug提示popViewArr这个数组下标越界

pod install 报错

The 'xxx' target has transitive dependencies that include statically linked binaries: (LSTCategory)

消失动画的问题

点击弹框消失的动画可以自定义嘛,比如我想缩放消失,目前框架提供的只有到顶,左,底,右

点击事件问题

在创建新的弹窗上,在创建一个collecitonView 所有item 不能点击,只有两个手指同时操作,一个手指按住,屏幕,另一个手指点击item 才能生效,应该是某个点击事件处理,响应了方法,响应链无法继续传递下去了

动画

能不能添加一个,底部单纯的弹入,弹出,不要淡入淡出的效果

customView 未添加到 window,调用 layoutIfNeeded 会有警告

作者你好,感谢你的代码开源!

这是我的代码使用,点击按钮,从底部弹出一个列表:

    @objc func buttonClick(_ button: UIButton) {
        let tableView = MyTableView(frame: CGRect(x: 0, y: 0, width: view.bounds.width, height: 200))
        
        let popView = LSTPopView.initWithCustomView(tableView, parentView: nil, popStyle: .smoothFromBottom, dismissStyle: .smoothToBottom)
        
        popView?.hemStyle = .bottom
        popView?.isClickBgDismiss = true
        popView?.pop()
    }

日志有如下警告:

[TableView] Warning once only: UITableView was told to layout its visible cells and other contents without being in the view hierarchy (the table view or one of its superviews has not been added to a window). This may cause bugs by forcing views inside the table view to load and perform layout without accurate information (e.g. table view bounds, trait collection, layout margins, safe area insets, etc), and will also cause unnecessary performance overhead due to extra layout passes. Make a symbolic breakpoint at UITableViewAlertForLayoutOutsideViewHierarchy to catch this in the debugger and see what caused this to occur, so you can avoid this action altogether if possible, or defer it until the table view has been added to a window. Table view: <UITableView: 0x7fd841840a00; frame = (0 0; 390 200); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x600002082e20>; layer = <CALayer: 0x600002edce20>; contentOffset: {0, 0}; contentSize: {390, 440}; adjustedContentInset: {0, 0, 0, 0}; dataSource: <OneWord.MyTableView: 0x7fd840413430; frame = (0 0; 390 200); gestureRecognizers = <NSArray: 0x600002066e50>; layer = <CALayer: 0x600002ed6920>>>

详情如图:

image

这里有个bug , `removePopView` 会 崩溃

/** 移除popView */
+ (void)removePopView:(LSTPopView *)popView {
    if (!popView) { return;}
    NSArray *arr = LSTPopViewM().popViewMarr;
    
    
    for (NSValue *v in arr) {
        LSTPopView *tPopView = v.nonretainedObjectValue;
        if ([tPopView isEqual:popView]) {
            [LSTPopViewM().popViewMarr removeObject:v];
            break;
            return;
        }
    }
}

这里 移除的时候, 应该判断 数组里的类型, 被添加到 数组里的, 不一定 全是 NSValue,
当 依次 添加 priority 越来越小的popview时, 因为没有 添加到 superview, 你 扔到 arr里的就是普通的popview, 所以会闪退

子视图有UITableView的时候点击cell被拦截了

首先非常喜欢楼主的LSTPopView
以下是我解决点击cell被拦截了的办法、或者楼主是否有更好的
#pragma mark-手势代理,解决和tableview点击发生的冲突
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITableViewCellContentView"]) {//判断如果点击的是tableView的cell,就把手势给关闭了
return NO;//关闭手势
}//否则手势存在
return YES;
}

Cocospod导入不加 use_frameworks!的问题

  • 作者您好,Cocospod引入LSTPopView,如果Podfile文件里不加 use_frameworks! pod install会报target has transitive dependencies that include statically linked binaries: (LSTCategory)错误

  • 怎样在加入use_frameworks!的情况下pod install导入成功呢?

定时器调试

demo里的定时器调试,倒计时未结束的时候,点击背景消失后,在点击显示弹窗,弹窗会闪一下,貌似是上一个定时任务结束了导致消失闪了一下

pan手势的问题

我在左侧测滑页面上放了一个tableView。
当我拖拽的手势在tableView上的时候,我是想侧滑的,结果y变了

Keyboard 和 customview 并不在同一坐标系,在presentViewController的view中弹出popview的话,customViewMaxY计算不对

Keyboard 和 customview 并不在同一坐标系,在presentViewController的view中弹出popview的话,customViewMaxY计算不对,可以这样修改:
- (void)keyboardWillShow:(NSNotification *)notification这个方法中修改:
CGFloat customViewMaxY = self.customView.pv_Bottom + self.avoidKeyboardSpace;
改成

CGRect cf = [self.customView convertRect:self.customView.bounds toView:[UIApplication sharedApplication].keyWindow];
CGFloat customViewMaxY = cf.origin.y + cf.size.height + self.avoidKeyboardSpace;

Bug和实现效果疑问

Bug

1、闪烁问题

问题:陆续弹出两个后,第二个会显示,第一个会被隐藏,当第二个还在展示而第一个消失时,界面会闪一下。
复现:Demo中常用示例场景,在点完 QQ顶部提示栏 后再点击 类微信/微博底部弹窗口 即可复现

2、定时器与生命周期

在使用窗口优先级来做弹窗效果时,第二个弹窗的优先级比第一个的低,并都为它们设置了自动消失时间,在第一个弹窗出现后,触发第二个弹窗,此时第二个不会展示,这是正常的,但是第二个弹窗的定时器和生命周期block(popViewDidPopBlock popViewWillPopBlock)会失效

功能疑问

1、排队展示

想实现如下效果:当弹出第一个后,第二个触发弹窗时,如果前面有弹窗展示了,则等待第一个弹窗消失后,再弹出第二个,并且都支持设置自动消失时间,这种该如何实现?

2、拖拽方向

是否可支持仅下拉和右滑拖拽消失,即拖拽同时只会是下拉或右滑,而不是右下方向移动

hemstyle会失效

masonry约束的自定义customview 宽高是根据subview的约束自适应

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.