Skip to content

Commit ac25264

Browse files
committed
optimized naming
1 parent 205d42b commit ac25264

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

TYAlertControllerDemo/TYAlertController/TYAlertController.m

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,18 +129,30 @@ - (void)addBackgroundView
129129
_backgroundView = backgroundView;
130130
}
131131
_backgroundView.translatesAutoresizingMaskIntoConstraints = NO;
132-
[self.view addSubview:_backgroundView];
132+
[self.view insertSubview:_backgroundView atIndex:0];
133133
[self.view addConstraintToView:_backgroundView edageInset:UIEdgeInsetsZero];
134134
}
135135

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+
136148
- (void)addSingleTapGesture
137149
{
138150
self.view.userInteractionEnabled = YES;
139151

140152
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap:)];
141153
singleTap.enabled = _backgoundTapDismissEnable;
142154

143-
[self.backgroundView addGestureRecognizer:singleTap];
155+
[_backgroundView addGestureRecognizer:singleTap];
144156
_singleTap = singleTap;
145157
}
146158

TYAlertControllerDemo/TYAlertController/TYShowAlertView.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
@interface TYShowAlertView : UIView
1212

1313
@property (nonatomic, weak, readonly) UIView *alertView;
14-
@property (nonatomic, weak) UIView *backgroundView;
14+
@property (nonatomic, strong) UIView *backgroundView;
1515

1616
@property (nonatomic, assign) BOOL backgoundTapDismissEnable; // default NO
1717
@property (nonatomic, assign) CGFloat alertViewOriginY; // default center Y

TYAlertControllerDemo/TYAlertController/TYShowAlertView.m

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,19 @@ - (void)addBackgroundView
8080
if (_backgroundView == nil) {
8181
UIView *backgroundView = [[UIView alloc]initWithFrame:self.bounds];
8282
backgroundView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.4];
83-
[self addSubview:backgroundView];
8483
_backgroundView = backgroundView;
85-
_backgroundView.translatesAutoresizingMaskIntoConstraints = NO;
86-
[self addConstraintToView:_backgroundView edageInset:UIEdgeInsetsZero];
8784
}
85+
[self insertSubview:_backgroundView atIndex:0];
86+
_backgroundView.translatesAutoresizingMaskIntoConstraints = NO;
87+
[self addConstraintToView:_backgroundView edageInset:UIEdgeInsetsZero];
8888
}
8989

9090
- (void)setBackgroundView:(UIView *)backgroundView
9191
{
9292
if (_backgroundView != backgroundView) {
9393
[_backgroundView removeFromSuperview];
94-
95-
[self addSubview:backgroundView];
9694
_backgroundView = backgroundView;
97-
_backgroundView.translatesAutoresizingMaskIntoConstraints = NO;
98-
[self addConstraintToView:_backgroundView edageInset:UIEdgeInsetsZero];
95+
[self addBackgroundView];
9996
[self addSingleGesture];
10097
}
10198
}

TYAlertControllerDemo/ViewController.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#import "UIImage+ImageEffects.h"
1212

1313
@interface ViewController ()
14+
1415
@end
1516

1617
@implementation ViewController
@@ -83,7 +84,8 @@ - (IBAction)blurEffectAlertViewAction:(id)sender {
8384
TYAlertController *alertController = [TYAlertController alertControllerWithAlertView:alertView preferredStyle:TYAlertControllerStyleAlert];
8485

8586
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;
8789

8890
//alertController.alertViewOriginY = 60;
8991
[self presentViewController:alertController animated:YES completion:nil];

0 commit comments

Comments
 (0)