ZZViewController.m 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. //
  2. // ZZViewController.m
  3. // ZZUIKit
  4. //
  5. // Created by bymiracles@163.com on 01/04/2021.
  6. // Copyright (c) 2021 bymiracles@163.com. All rights reserved.
  7. //
  8. #import "ZZViewController.h"
  9. #import <ZZUIKit/ZZUIKitEx.h>
  10. #import <ZZUIKit/ZZDialog.h>
  11. #import <ZZUIKit/ZZDialogViewController.h>
  12. #import <ZZUIKit/ZZTextWidget.h>
  13. CGFloat const handleBarH = 200;
  14. @interface ZZViewController ()<ZZDialogDelegate,ZZDialogHandleDelegate>
  15. @property(nonatomic,strong) ZZDialog *dialog;
  16. @property(nonatomic,strong) ZZDialogViewController *dialogVC;
  17. @property (strong, nonatomic) IBOutlet ZZTextWidget *textWidget;
  18. @property(nonatomic,strong) NSArray *titles;
  19. @end
  20. @implementation ZZViewController
  21. - (void)viewDidLoad
  22. {
  23. [super viewDidLoad];
  24. self.view.backgroundColor = [UIColor blueColor];
  25. // Do any additional setup after loading the view, typically from a nib.
  26. self.dialog.cancelBtn = [UIButton buttonWithType:UIButtonTypeContactAdd];
  27. self.dialogVC.dialog.cancelBtn = [UIButton buttonWithType:UIButtonTypeContactAdd];
  28. self.dialogVC.blurStyle = UIBlurEffectStyleLight;
  29. self.textWidget.maxLength = 10;
  30. self.textWidget.placeholder = @"请输入内容";
  31. }
  32. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
  33. switch (section) {
  34. case 0:
  35. {
  36. UILabel *lab = [UILabel new];
  37. lab.text = @"直接添加到父视图";
  38. return lab;
  39. }
  40. break;
  41. default:
  42. {
  43. UILabel *lab = [UILabel new];
  44. lab.text = @"present";
  45. return lab;
  46. }
  47. break;
  48. }
  49. }
  50. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  51. return 80;
  52. }
  53. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  54. if (indexPath.section == 0) {
  55. self.dialog.cancelPosition = indexPath.row;
  56. [self configDialog:self.dialog withIndex:indexPath.row];
  57. [self.view addSubview:self.dialog];
  58. }else if (indexPath.section == 1){
  59. self.dialogVC.dialog.cancelPosition = indexPath.row;
  60. [self configDialog:self.dialogVC.dialog withIndex:indexPath.row];
  61. [self presentViewController:self.dialogVC animated:false completion:nil];
  62. }
  63. }
  64. - (IBAction)deleteBtnShow:(UISwitch *)sender {
  65. _dialog.cancelBtn = sender.on ? [UIButton buttonWithType:UIButtonTypeContactAdd] : nil;
  66. _dialogVC.dialog.cancelBtn = sender.on ? [UIButton buttonWithType:UIButtonTypeContactAdd] : nil;
  67. }
  68. - (IBAction)blurOrMask:(UISwitch *)sender {
  69. if (sender.on) {
  70. _dialogVC.blurStyle = UIBlurEffectStyleLight;
  71. }else{
  72. _dialogVC.maskColor = [UIColor colorWithWhite:0 alpha:0.8];
  73. }
  74. }
  75. -(void)configDialog:(ZZDialog *)dialog withIndex:(NSInteger)index{
  76. switch (index) {
  77. case 1:
  78. dialog.cancelMargin = ZZDialogCancelMarginMake(10, 10);
  79. break;
  80. default:
  81. dialog.cancelMargin = ZZDialogCancelMarginMake(30, 10);
  82. break;
  83. }
  84. }
  85. -(CGRect)preferredFrameForDialog:(ZZDialog *)dialog{
  86. return CGRectMake(SCREEN_W()/6, SCREEN_H()/4, SCREEN_W()*4/6, SCREEN_H()/2);
  87. }
  88. #pragma mark -- ZZDialogContenDelegate
  89. -(CGRect)preferredFrameForContentInDialog:(ZZDialog *)dialog{
  90. return CGRectMake(0, 0, dialog.zz_width, dialog.zz_height - handleBarH);
  91. }
  92. -(__kindof UIView *)viewForContentInDialog:(ZZDialog *)dialog{
  93. UIView *view = [UIView new];
  94. view.backgroundColor = [UIColor redColor];
  95. view.layer.borderColor = [UIColor purpleColor].CGColor;
  96. view.layer.borderWidth = 3;
  97. return view;
  98. }
  99. #pragma mark -- ZZDialogHandleDelegate
  100. -(CGRect)preferredFrameForHandleInDialog:(ZZDialog *)dialog{
  101. return CGRectMake(0, dialog.zz_height - handleBarH, dialog.zz_width, handleBarH);
  102. }
  103. -(NSArray<NSDictionary *> *)itemsForHandleInDialog:(ZZDialog *)dialog{
  104. return @[
  105. @{ZZTitleKey:@"que定",
  106. ZZFontKey:[UIFont systemFontOfSize:20],
  107. ZZTitleColorKey:[UIColor purpleColor],
  108. ZZActionKey:^(){
  109. [dialog dismiss];
  110. }
  111. },
  112. @{ZZTitleKey:@"取消",
  113. ZZFontKey:[UIFont systemFontOfSize:20],
  114. ZZTitleColorKey:[UIColor grayColor],
  115. ZZActionKey:^(){
  116. [dialog dismiss];
  117. }
  118. },
  119. @{ZZTitleKey:@"再想想",
  120. ZZFontKey:[UIFont systemFontOfSize:20],
  121. ZZTitleColorKey:[UIColor grayColor],
  122. ZZActionKey:^(){
  123. [dialog dismiss];
  124. }
  125. },
  126. ];
  127. }
  128. -(ZZDialog *)dialog{
  129. if(!_dialog){
  130. _dialog = [[ZZDialog alloc] initWithFrame:CGRectMake(SCREEN_W()/4, SCREEN_H()/4, SCREEN_W()/2, SCREEN_H()/2)];
  131. _dialog.contentDelegate = self;
  132. _dialog.handleDelegate = self;
  133. _dialog.backgroundColor = [UIColor greenColor];
  134. }
  135. return _dialog;
  136. }
  137. -(ZZDialogViewController *)dialogVC{
  138. if(!_dialogVC){
  139. _dialogVC = [ZZDialogViewController new];
  140. _dialogVC.maskColor = [UIColor colorWithWhite:0 alpha:0.7];
  141. _dialogVC.dialogDelegate = self;
  142. _dialogVC.handleDelegate = self;
  143. _dialogVC.dialog.backgroundColor = [UIColor greenColor];
  144. }
  145. return _dialogVC;
  146. }
  147. - (void)didReceiveMemoryWarning
  148. {
  149. [super didReceiveMemoryWarning];
  150. // Dispose of any resources that can be recreated.
  151. }
  152. @end