上拉式弹窗的实现

  有些弹窗如果点击按钮的同时就出现一个弹窗就显得有的突兀,这次实现的效果是点击按钮的同时弹窗由下往上弹出来,添加了动画效果:

1、首先创建一个弹出的View类,

在HTAlertView.h中:

@property (nonatomic, strong) void (^backBtnActionBlock)();

@property (weak, nonatomic) IBOutlet UIView *myView;

@property(nonatomic,strong) UIControl *huiseControl;

- (void)showInView:(UIView *) view;

+ (instancetype)getSimpleView;

2、在HTAlertView.m中:

- (void)awakeFromNib{
    
    _huiseControl=[[UIControl alloc]initWithFrame:CGRectMake(0, 0, UIBounds.size.width, UIBounds.size.height)];
    _huiseControl.backgroundColor=RGBACOLOR(0, 0, 0, 0.4);
    [_huiseControl addTarget:self action:@selector(huiseControlClick) forControlEvents:UIControlEventTouchUpInside];
    _huiseControl.alpha=0;
    self.backgroundColor = [UIColor whiteColor];
}

+ (instancetype)getSimpleView{
    
    NSArray *objs = [[NSBundle mainBundle] loadNibNamed:@"HTAlertView" owner:nil options:nil];
    return [objs lastObject];
}
- (void)showInView:(UIView *) view {

    if (_huiseControl.superview==nil) {
        [view addSubview:_huiseControl];
    }
    [UIView animateWithDuration:0.2 animations:^{
        _huiseControl.alpha=1;
    }];
    CATransition *animation = [CATransition  animation];
    animation.delegate = self;
    animation.duration = 0.2f;
    animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    animation.type = kCATransitionPush;
    animation.subtype = kCATransitionFromTop;
    [self.layer addAnimation:animation forKey:@"animation1"];
    self.frame = CGRectMake(0,view.frame.size.height - 355, [UIScreen mainScreen].bounds.size.width, 355);
    [view addSubview:self];

}
- (void)hideInView {
    
    self.hidden = YES;
    CATransition *animation = [CATransition  animation];
    animation.delegate = self;
    animation.duration = 0.2f;
    animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    animation.type = kCATransitionPush;
    animation.subtype = kCATransitionFromBottom;
    [self.layer addAnimation:animation forKey:@"animtion2"];
    [UIView animateWithDuration:0.2 animations:^{
        _huiseControl.alpha=0;
    }completion:^(BOOL finished) {
        [self removeFromSuperview];
        [_huiseControl removeFromSuperview];
    }];
   
}
- (IBAction)btnClick:(UIButton *)sender {
    
    if (self.backBtnActionBlock) {
        
        self.backBtnActionBlock();
    }
}

-(void)huiseControlClick{
    
    [self hideInView];
}

其中

#define UIBounds [[UIScreen mainScreen] bounds] //window外框大小
#define RGBACOLOR(r,g,b,a) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:a]

最后在viewController中要弹窗的button实现方法即可

- (void)popupButtonClick
{
    HTAlertView *alert = [HTAlertView getSimpleView];
    
    alert.backBtnActionBlock = ^(){
      
        NSLog(@"sdgvet4wfdscx");
    };
    
    [alert showInView:self.view];
}

 其中有代码块可以回调得到View中的按钮触发

转载于:https://www.cnblogs.com/h-tao/p/5635377.html

实现显示弹窗的效果,可以使用 `uni-popup` 组件来实现。在 `scrolltolower` 事件中,当用户滑动到页面底部时,弹出弹窗显示更多数据。 首先,在 `template` 中使用 `uni-popup` 组件,并设置 `show` 属性为 `false`,表示一开始不显示弹窗: ``` <template> <view> <uni-scroll-view class="scroll-view" :scrolltolower="showPopup"> <!-- 数据列表 --> </uni-scroll-view> <uni-popup v-model="show" position="bottom"> <!-- 弹窗内容 --> </uni-popup> </view> </template> ``` 然后在 `script` 中定义 `showPopup` 方法来显示弹窗: ``` <script> export default { data() { return { show: false, // 是否显示弹窗 dataList: [], // 数据列表 pageNo: 1, // 当前页码 pageSize: 10, // 每页数据条数 hasMoreData: true // 是否还有更多数据 }; }, methods: { showPopup() { if (!this.hasMoreData) return; // 如果没有更多数据,则不再显示弹窗 // 发送请求获取数据 uni.request({ url: 'xxx', data: { pageNo: this.pageNo + 1, pageSize: this.pageSize }, success: res => { // 将新数据添加到列表中 this.dataList = this.dataList.concat(res.data.list); // 判断是否还有更多数据 if (res.data.list.length < this.pageSize) { this.hasMoreData = false; } // 更新页码 this.pageNo += 1; // 显示弹窗 this.show = true; } }); } } }; </script> ``` 在 `showPopup` 方法中,首先判断是否还有更多数据需要加载,如果没有则直接返回。然后发送请求获取数据,将新数据添加到列表中,并更新页码。最后判断是否还有更多数据需要加载,如果没有则将 `hasMoreData` 设置为 `false`,表示不再加载数据。然后将 `show` 属性设置为 `true`,表示显示弹窗。 这样,当用户滑动到页面底部时,就会触发 `scrolltolower` 事件,自动加载更多数据并显示弹窗
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值