IOS7、8模态半透明弹出框

           //源Controller中跳转方法实现
            MKDialogController *controller = [[MKDialogController alloc] init];
            controller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
            if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
                controller.providesPresentationContextTransitionStyle = YES;
                controller.definesPresentationContext = YES;
                controller.modalPresentationStyle = UIModalPresentationOverCurrentContext;
                [self presentViewController:controller animated:YES completion:nil];
            } else {
                self.view.window.rootViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
                [self presentViewController:controller animated:NO completion:nil];
                self.view.window.rootViewController.modalPresentationStyle = UIModalPresentationFullScreen;
            }

    self.view.backgroundColor = [UIColor clearColor];
    UIView *alphaView = [[UIView alloc] initWithFrame:self.view.frame];
    UIView *baseView = [[UIView alloc] initWithFrame:self.view.frame];
    alphaView.backgroundColor = [UIColor clearColor];
    baseView.backgroundColor = [UIColor blackColor];
    baseView.alpha = 0.7;
    [self.view addSubview:baseView];
    [self.view addSubview:alphaView];


  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用 Stack 组件来实现模态弹出比较常见的方法是将模态放在 Stack 的顶部,然后通过控制模态的可见性来实现弹出和关闭。具体步骤如下: 1. 创建一个 Stack 组件,并将模态放在 Stack 的顶部。 ```dart Stack( children: [ // 页面内容 Scaffold( appBar: AppBar( title: Text('Stack 弹窗示例'), ), body: Center( child: ElevatedButton( child: Text('弹出模态'), onPressed: () { // TODO: 弹出模态 }, ), ), ), // 模态 Visibility( visible: _isModalVisible, // 控制模态的可见性 child: Container( width: double.infinity, height: double.infinity, color: Colors.black45, child: Center( child: Card( child: Padding( padding: EdgeInsets.all(16.0), child: Column( mainAxisSize: MainAxisSize.min, children: [ Text('模态内容'), ElevatedButton( child: Text('关闭模态'), onPressed: () { // TODO: 关闭模态 }, ), ], ), ), ), ), ), ), ], ) ``` 2. 当用户点击“弹出模态”按钮时,将 `_isModalVisible` 设置为 `true`,这样模态就会显示出来。 ```dart onPressed: () { setState(() { _isModalVisible = true; }); }, ``` 3. 当用户点击“关闭模态”按钮时,将 `_isModalVisible` 设置为 `false`,这样模态就会隐藏起来。 ```dart onPressed: () { setState(() { _isModalVisible = false; }); }, ``` 这样就可以使用 Stack 组件来实现模态弹出了。注意,在实际的项目中,你可能还需要对模态的位置、大小、动画等进行进一步的调整和优化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值