-
Notifications
You must be signed in to change notification settings - Fork 240
Expand file tree
/
Copy pathViewController.m
More file actions
183 lines (131 loc) · 7.01 KB
/
ViewController.m
File metadata and controls
183 lines (131 loc) · 7.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
//
// ViewController.m
// TYAlertControllerDemo
//
// Created by tanyang on 15/9/1.
// Copyright (c) 2015年 tanyang. All rights reserved.
//
#import "ViewController.h"
// contain this header
#import "UIView+TYAlertView.h"
// if you want blur efffect contain this
#import "TYAlertController+BlurEffects.h"
#import "SettingModelView.h"
#import "ShareView.h"
#define kScreenWidth [UIScreen mainScreen].bounds.size.width
#define kScreenHeight [UIScreen mainScreen].bounds.size.height
#define kCurrentWindowCenter [UIApplication sharedApplication].keyWindow.center
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)showAlertViewAction:(id)sender {
TYAlertView *alertView = [TYAlertView alertViewWithTitle:@"TYAlertView" message:@"This is a message, the alert view containt text and textfiled. "];
[alertView addAction:[TYAlertAction actionWithTitle:@"取消" style:TYAlertActionStyleCancel handler:^(TYAlertAction *action) {
NSLog(@"%@",action.title);
}]];
// 弱引用alertView 否则 会循环引用
__typeof (alertView) __weak weakAlertView = alertView;
[alertView addAction:[TYAlertAction actionWithTitle:@"确定" style:TYAlertActionStyleDestructive handler:^(TYAlertAction *action) {
NSLog(@"%@",action.title);
for (UITextField *textField in weakAlertView.textFieldArray) {
NSLog(@"%@",textField.text);
}
}]];
[alertView addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"请输入账号";
}];
[alertView addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"请输入密码";
}];
// first way to show
TYAlertController *alertController = [TYAlertController alertControllerWithAlertView:alertView preferredStyle:TYAlertControllerStyleAlert];
[alertController setViewWillShowHandler:^(UIView *alertView) {
NSLog(@"ViewWillShow");
}];
[alertController setViewDidShowHandler:^(UIView *alertView) {
NSLog(@"ViewDidShow");
}];
[alertController setViewWillHideHandler:^(UIView *alertView) {
NSLog(@"ViewWillHide");
}];
[alertController setViewDidHideHandler:^(UIView *alertView) {
NSLog(@"ViewDidHide");
}];
[alertController setDismissComplete:^{
NSLog(@"DismissComplete");
}];
//alertController.alertViewOriginY = 60;
[self presentViewController:alertController animated:YES completion:nil];
// second way ,use UIView Category
//[alertView showInController:self preferredStyle:TYAlertControllerStyleAlert];
}
- (IBAction)showActionSheetAction:(id)sender {
TYAlertView *alertView = [TYAlertView alertViewWithTitle:@"TYAlertView" message:@"This is a message, the alert view style is actionsheet. "];
[alertView addAction:[TYAlertAction actionWithTitle:@"默认2" style:TYAlertActionStyleDefault handler:^(TYAlertAction *action) {
NSLog(@"%@",action.title);
}]];
[alertView addAction:[TYAlertAction actionWithTitle:@"默认1" style:TYAlertActionStyleDefault handler:^(TYAlertAction *action) {
NSLog(@"%@",action.title);
}]];
[alertView addAction:[TYAlertAction actionWithTitle:@"删除" style:TYAlertActionStyleDestructive handler:^(TYAlertAction *action) {
NSLog(@"%@",action.title);
}]];
[alertView addAction:[TYAlertAction actionWithTitle:@"取消" style:TYAlertActionStyleCancel handler:^(TYAlertAction *action) {
NSLog(@"%@",action.title);
}]];
TYAlertController *alertController = [TYAlertController alertControllerWithAlertView:alertView preferredStyle:TYAlertControllerStyleActionSheet];
[self presentViewController:alertController animated:YES completion:nil];
}
- (IBAction)blurEffectAlertViewAction:(id)sender {
ShareView *shareView = [ShareView createViewFromNib];
TYAlertController *alertController = [TYAlertController alertControllerWithAlertView:shareView preferredStyle:TYAlertControllerStyleAlert];
// blur effect
[alertController setBlurEffectWithView:self.view];
//alertController.alertViewOriginY = 60;
[self presentViewController:alertController animated:YES completion:nil];
}
- (IBAction)dropdwonAnimationAction:(id)sender {
TYAlertView *alertView = [TYAlertView alertViewWithTitle:@"TYAlertView" message:@"This is a message, the alert view containt dropdwon animation. "];
[alertView addAction:[TYAlertAction actionWithTitle:@"取消" style:TYAlertActionStyleCancel handler:^(TYAlertAction *action) {
NSLog(@"%@",action.title);
}]];
TYAlertController *alertController = [TYAlertController alertControllerWithAlertView:alertView preferredStyle:TYAlertControllerStyleAlert transitionAnimation:TYAlertTransitionAnimationDropDown];
[self presentViewController:alertController animated:YES completion:nil];
// or show,use UIView Category
//[alertView showInController:self preferredStyle:TYAlertControllerStyleAlert];
}
- (IBAction)costomActonSheetAction:(id)sender {
// customview from xib
SettingModelView *settingModelView = [SettingModelView createViewFromNib];
// fisrt way to show ,use UIView Category
// [settingModelView showInController:self preferredStyle:TYAlertControllerStyleActionSheet backgoundTapDismissEnable:YES];
// second way to show
TYAlertController *alertController = [TYAlertController alertControllerWithAlertView:settingModelView preferredStyle:TYAlertControllerStyleActionSheet];
alertController.backgoundTapDismissEnable = YES;
[self presentViewController:alertController animated:YES completion:nil];
}
- (IBAction)showAlertViewInWindowAction:(id)sender {
TYAlertView *alertView = [TYAlertView alertViewWithTitle:@"TYAlertView" message:@"A message should be a short, but it can support long message, hahahhahahahahhahahahahhaahahhahahahahahhahahahahhahahahahahhahahahahahhahahahhahahhahahahahh. (NSTextAlignmentCenter)"];
[alertView addAction:[TYAlertAction actionWithTitle:@"取消" style:TYAlertActionStyleCancel handler:^(TYAlertAction *action) {
}]];
[alertView addAction:[TYAlertAction actionWithTitle:@"确定" style:TYAlertActionStyleDestructive handler:^(TYAlertAction *action) {
}]];
// first way to show ,use UIView Category
[alertView showInWindowWithCenter:kCurrentWindowCenter backgoundTapDismissEnable:YES];
// second way to show
//[TYShowAlertView showAlertViewWithView:alertView originY:200 backgoundTapDismissEnable:YES];
}
- (IBAction)customViewInWindowAction:(id)sender {
ShareView *shareView = [ShareView createViewFromNib];
// use UIView Category
[shareView showInWindowWithCenter:CGPointMake(kScreenWidth / 2.0, 380)];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end