123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- //
- // ZZViewController.m
- // ZZUIKit
- //
- // Created by bymiracles@163.com on 01/04/2021.
- // Copyright (c) 2021 bymiracles@163.com. All rights reserved.
- //
- #import "ZZViewController.h"
- #import <ZZUIKit/ZZUIKitEx.h>
- #import <ZZUIKit/ZZDialog.h>
- #import <ZZUIKit/ZZDialogViewController.h>
- #import <ZZUIKit/ZZTextWidget.h>
- CGFloat const handleBarH = 200;
- @interface ZZViewController ()<ZZDialogDelegate,ZZDialogHandleDelegate>
- @property(nonatomic,strong) ZZDialog *dialog;
- @property(nonatomic,strong) ZZDialogViewController *dialogVC;
- @property (strong, nonatomic) IBOutlet ZZTextWidget *textWidget;
- @property(nonatomic,strong) NSArray *titles;
- @end
- @implementation ZZViewController
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- self.view.backgroundColor = [UIColor blueColor];
- // Do any additional setup after loading the view, typically from a nib.
- self.dialog.cancelBtn = [UIButton buttonWithType:UIButtonTypeContactAdd];
- self.dialogVC.dialog.cancelBtn = [UIButton buttonWithType:UIButtonTypeContactAdd];
- self.dialogVC.blurStyle = UIBlurEffectStyleLight;
- self.textWidget.maxLength = 10;
- self.textWidget.placeholder = @"请输入内容";
- }
- -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
- switch (section) {
- case 0:
- {
- UILabel *lab = [UILabel new];
- lab.text = @"直接添加到父视图";
- return lab;
- }
- break;
-
- default:
- {
- UILabel *lab = [UILabel new];
- lab.text = @"present";
- return lab;
- }
- break;
- }
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
- return 80;
- }
- -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- if (indexPath.section == 0) {
- self.dialog.cancelPosition = indexPath.row;
- [self configDialog:self.dialog withIndex:indexPath.row];
- [self.view addSubview:self.dialog];
- }else if (indexPath.section == 1){
- self.dialogVC.dialog.cancelPosition = indexPath.row;
- [self configDialog:self.dialogVC.dialog withIndex:indexPath.row];
- [self presentViewController:self.dialogVC animated:false completion:nil];
- }
-
- }
- - (IBAction)deleteBtnShow:(UISwitch *)sender {
- _dialog.cancelBtn = sender.on ? [UIButton buttonWithType:UIButtonTypeContactAdd] : nil;
- _dialogVC.dialog.cancelBtn = sender.on ? [UIButton buttonWithType:UIButtonTypeContactAdd] : nil;
- }
- - (IBAction)blurOrMask:(UISwitch *)sender {
- if (sender.on) {
- _dialogVC.blurStyle = UIBlurEffectStyleLight;
- }else{
- _dialogVC.maskColor = [UIColor colorWithWhite:0 alpha:0.8];
- }
- }
- -(void)configDialog:(ZZDialog *)dialog withIndex:(NSInteger)index{
- switch (index) {
- case 1:
- dialog.cancelMargin = ZZDialogCancelMarginMake(10, 10);
- break;
- default:
- dialog.cancelMargin = ZZDialogCancelMarginMake(30, 10);
- break;
- }
- }
- -(CGRect)preferredFrameForDialog:(ZZDialog *)dialog{
- return CGRectMake(SCREEN_W()/6, SCREEN_H()/4, SCREEN_W()*4/6, SCREEN_H()/2);
- }
- #pragma mark -- ZZDialogContenDelegate
- -(CGRect)preferredFrameForContentInDialog:(ZZDialog *)dialog{
- return CGRectMake(0, 0, dialog.zz_width, dialog.zz_height - handleBarH);
- }
- -(__kindof UIView *)viewForContentInDialog:(ZZDialog *)dialog{
- UIView *view = [UIView new];
- view.backgroundColor = [UIColor redColor];
- view.layer.borderColor = [UIColor purpleColor].CGColor;
- view.layer.borderWidth = 3;
- return view;
- }
- #pragma mark -- ZZDialogHandleDelegate
- -(CGRect)preferredFrameForHandleInDialog:(ZZDialog *)dialog{
- return CGRectMake(0, dialog.zz_height - handleBarH, dialog.zz_width, handleBarH);
- }
- -(NSArray<NSDictionary *> *)itemsForHandleInDialog:(ZZDialog *)dialog{
- return @[
- @{ZZTitleKey:@"que定",
- ZZFontKey:[UIFont systemFontOfSize:20],
- ZZTitleColorKey:[UIColor purpleColor],
- ZZActionKey:^(){
- [dialog dismiss];
- }
- },
- @{ZZTitleKey:@"取消",
- ZZFontKey:[UIFont systemFontOfSize:20],
- ZZTitleColorKey:[UIColor grayColor],
- ZZActionKey:^(){
- [dialog dismiss];
- }
- },
- @{ZZTitleKey:@"再想想",
- ZZFontKey:[UIFont systemFontOfSize:20],
- ZZTitleColorKey:[UIColor grayColor],
- ZZActionKey:^(){
- [dialog dismiss];
- }
- },
- ];
- }
- -(ZZDialog *)dialog{
- if(!_dialog){
- _dialog = [[ZZDialog alloc] initWithFrame:CGRectMake(SCREEN_W()/4, SCREEN_H()/4, SCREEN_W()/2, SCREEN_H()/2)];
- _dialog.contentDelegate = self;
- _dialog.handleDelegate = self;
- _dialog.backgroundColor = [UIColor greenColor];
- }
- return _dialog;
- }
- -(ZZDialogViewController *)dialogVC{
- if(!_dialogVC){
- _dialogVC = [ZZDialogViewController new];
- _dialogVC.maskColor = [UIColor colorWithWhite:0 alpha:0.7];
- _dialogVC.dialogDelegate = self;
- _dialogVC.handleDelegate = self;
- _dialogVC.dialog.backgroundColor = [UIColor greenColor];
- }
- return _dialogVC;
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- @end
|