File tree Expand file tree Collapse file tree 4 files changed +22
-11
lines changed Expand file tree Collapse file tree 4 files changed +22
-11
lines changed Original file line number Diff line number Diff line change @@ -129,18 +129,30 @@ - (void)addBackgroundView
129
129
_backgroundView = backgroundView;
130
130
}
131
131
_backgroundView.translatesAutoresizingMaskIntoConstraints = NO ;
132
- [self .view addSubview : _backgroundView];
132
+ [self .view insertSubview : _backgroundView atIndex: 0 ];
133
133
[self .view addConstraintToView: _backgroundView edageInset: UIEdgeInsetsZero];
134
134
}
135
135
136
+ - (void )setBackgroundView : (UIView *)backgroundView
137
+ {
138
+ if (_backgroundView == nil ) {
139
+ _backgroundView = backgroundView;
140
+ } else if (_backgroundView != backgroundView) {
141
+ [_backgroundView removeFromSuperview ];
142
+ _backgroundView = backgroundView;
143
+ [self addBackgroundView ];
144
+ [self addSingleTapGesture ];
145
+ }
146
+ }
147
+
136
148
- (void )addSingleTapGesture
137
149
{
138
150
self.view .userInteractionEnabled = YES ;
139
151
140
152
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc ] initWithTarget: self action: @selector (singleTap: )];
141
153
singleTap.enabled = _backgoundTapDismissEnable;
142
154
143
- [self .backgroundView addGestureRecognizer: singleTap];
155
+ [_backgroundView addGestureRecognizer: singleTap];
144
156
_singleTap = singleTap;
145
157
}
146
158
Original file line number Diff line number Diff line change 11
11
@interface TYShowAlertView : UIView
12
12
13
13
@property (nonatomic , weak , readonly ) UIView *alertView;
14
- @property (nonatomic , weak ) UIView *backgroundView;
14
+ @property (nonatomic , strong ) UIView *backgroundView;
15
15
16
16
@property (nonatomic , assign ) BOOL backgoundTapDismissEnable; // default NO
17
17
@property (nonatomic , assign ) CGFloat alertViewOriginY; // default center Y
Original file line number Diff line number Diff line change @@ -80,22 +80,19 @@ - (void)addBackgroundView
80
80
if (_backgroundView == nil ) {
81
81
UIView *backgroundView = [[UIView alloc ]initWithFrame:self .bounds];
82
82
backgroundView.backgroundColor = [UIColor colorWithRed: 0 green: 0 blue: 0 alpha: 0.4 ];
83
- [self addSubview: backgroundView];
84
83
_backgroundView = backgroundView;
85
- _backgroundView.translatesAutoresizingMaskIntoConstraints = NO ;
86
- [self addConstraintToView: _backgroundView edageInset: UIEdgeInsetsZero];
87
84
}
85
+ [self insertSubview: _backgroundView atIndex: 0 ];
86
+ _backgroundView.translatesAutoresizingMaskIntoConstraints = NO ;
87
+ [self addConstraintToView: _backgroundView edageInset: UIEdgeInsetsZero];
88
88
}
89
89
90
90
- (void )setBackgroundView : (UIView *)backgroundView
91
91
{
92
92
if (_backgroundView != backgroundView) {
93
93
[_backgroundView removeFromSuperview ];
94
-
95
- [self addSubview: backgroundView];
96
94
_backgroundView = backgroundView;
97
- _backgroundView.translatesAutoresizingMaskIntoConstraints = NO ;
98
- [self addConstraintToView: _backgroundView edageInset: UIEdgeInsetsZero];
95
+ [self addBackgroundView ];
99
96
[self addSingleGesture ];
100
97
}
101
98
}
Original file line number Diff line number Diff line change 11
11
#import " UIImage+ImageEffects.h"
12
12
13
13
@interface ViewController ()
14
+
14
15
@end
15
16
16
17
@implementation ViewController
@@ -83,7 +84,8 @@ - (IBAction)blurEffectAlertViewAction:(id)sender {
83
84
TYAlertController *alertController = [TYAlertController alertControllerWithAlertView: alertView preferredStyle: TYAlertControllerStyleAlert];
84
85
85
86
UIImage *blurImage =[[UIImage snapshotImageWithView: self .view] applyLightEffect ];
86
- alertController.backgroundView = [[UIImageView alloc ]initWithImage:blurImage];
87
+ UIImageView *blurImageView = [[UIImageView alloc ]initWithImage:blurImage];
88
+ alertController.backgroundView = blurImageView;
87
89
88
90
// alertController.alertViewOriginY = 60;
89
91
[self presentViewController: alertController animated: YES completion: nil ];
You can’t perform that action at this time.
0 commit comments