Permalink
Browse files

update

  • Loading branch information...
1 parent 44958a8 commit 6bdf479606f187328e7d6e2594be2e3a0861d0d2 @yulingtianxia committed Oct 10, 2016
Showing with 45 additions and 28 deletions.
  1. +1 −1 Example/TBAlertControllerDemo/ViewController.m
  2. +44 −27 Source/TBActionSheet/TBActionSheet.m
@@ -24,7 +24,7 @@ - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_leakTest = [NSObject new];
- [self runSpinAnimationOnView:self.imageView duration:1 rotations:1 repeat:HUGE_VALF];
+// [self runSpinAnimationOnView:self.imageView duration:1 rotations:1 repeat:HUGE_VALF];
}
- (void) runSpinAnimationOnView:(UIView*)view duration:(CGFloat)duration rotations:(CGFloat)rotations repeat:(float)repeat;
@@ -31,7 +31,8 @@ @interface TBActionSheet ()
@property (nonatomic,strong,nullable,readwrite) UILabel *messageLabel;
@property (weak, nonatomic, readwrite) UIWindow *previousKeyWindow;
@property (strong, nonatomic) UIWindow *window;
-@property (strong, nonatomic) CADisplayLink *displayLink;
+//@property (weak, nonatomic) NSTimer *timer;
+@property (strong, nonatomic, nullable) UIImage *originalBackgroundImage;
@property (strong, nonatomic) NSMutableArray<TBBlurEffectBlock> *blurBlocks;
@end
@@ -76,7 +77,9 @@ - (instancetype)init
//set default values
_cancelButtonIndex = -1;
_destructiveButtonIndex = -1;
- self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(refreshBlurEffect)];
+// self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(refreshBlurEffect)];
+// self.displayLink.frameInterval = 2;
+
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarDidChangeOrientation:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
}
return self;
@@ -131,7 +134,7 @@ - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message dele
- (void)dealloc
{
- [self.displayLink invalidate];
+// [self.displayLink invalidate];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
@@ -424,25 +427,23 @@ - (void)setupStyle
CGFloat containerHeight = self.actionContainer.bounds.size.height;
- __block UIImage *originalBackgroundImage = [self screenShotRect:CGRectMake(kContainerLeft, kScreenHeight-containerHeight, self.sheetWidth, containerHeight)];
- TBBlurEffectBlock blurBlock = ^void() {
- originalBackgroundImage = [self screenShotRect:CGRectMake(kContainerLeft, kScreenHeight-containerHeight, self.sheetWidth, containerHeight)];
- };
- [self.blurBlocks addObject:blurBlock];
+ self.originalBackgroundImage = [self screenShotRect:CGRectMake(kContainerLeft, kScreenHeight-containerHeight, self.sheetWidth, containerHeight)];
- CGFloat heightLargerThanImage = containerHeight - originalBackgroundImage.size.height;// 计算 container 的高度超出截图的数值
+ CGFloat heightLargerThanImage = containerHeight - self.originalBackgroundImage.size.height;// 计算 container 的高度超出截图的数值
__block BOOL useBoxBlurEffect = NO;
- self.displayLink.paused = YES;
+// self.displayLink.paused = YES;
if (!self.isBackgroundTransparentEnabled) {
if (self.isBlurEffectEnabled) {
if (![self.actionContainer useSystemBlurEffect]) {
TBWeakSelf(self);
TBBlurEffectBlock blurBlock = ^void() {
TBStrongSelf(self);
- UIImage *backgroundImage = [originalBackgroundImage drn_boxblurImageWithBlur:blurRadius withTintColor:[self.ambientColor colorWithAlphaComponent:0.5]];
- self.actionContainer.image = backgroundImage;
+ UIImage *backgroundImage = [self.originalBackgroundImage drn_boxblurImageWithBlur:blurRadius withTintColor:[self.ambientColor colorWithAlphaComponent:0.5]];
+ dispatch_async(dispatch_get_main_queue(), ^{
+ self.actionContainer.image = backgroundImage;
+ });
};
[self.blurBlocks addObject:blurBlock];
useBoxBlurEffect = YES;
@@ -519,7 +520,7 @@ - (void)setupStyle
else {
targetFrame = sourceFrame;
}
- UIImage *cuttedImage = [self cutFromImage:originalBackgroundImage inRect:targetFrame];
+ UIImage *cuttedImage = [self cutFromImage:self.originalBackgroundImage inRect:targetFrame];
return cuttedImage;
};
@@ -533,7 +534,9 @@ - (void)setupStyle
TBBlurEffectBlock blurBlock = ^void() {
TBStrongSelf(self);
UIImage *backgroundImage = [cutOriginalBackgroundImageInRect(self.actionContainer.header.frame) drn_boxblurImageWithBlur:blurRadius withTintColor:self.ambientColor];
- self.actionContainer.header.image = backgroundImage;
+ dispatch_async(dispatch_get_main_queue(), ^{
+ self.actionContainer.header.image = backgroundImage;
+ });
};
[self.blurBlocks addObject:blurBlock];
useBoxBlurEffect = YES;
@@ -560,7 +563,9 @@ - (void)setupStyle
TBBlurEffectBlock blurBlock = ^void() {
TBStrongSelf(self);
UIImage *backgroundImage = [cutOriginalBackgroundImageInRect(self.actionContainer.custom.frame) drn_boxblurImageWithBlur:blurRadius withTintColor:self.ambientColor];
- self.actionContainer.custom.image = backgroundImage;
+ dispatch_async(dispatch_get_main_queue(), ^{
+ self.actionContainer.custom.image = backgroundImage;
+ });
};
[self.blurBlocks addObject:blurBlock];
useBoxBlurEffect = YES;
@@ -590,9 +595,11 @@ - (void)setupStyle
UIImage *cuttedImage = cutOriginalBackgroundImageInRect(obj.frame);
UIImage *backgroundImageNormal = [cuttedImage drn_boxblurImageWithBlur:blurRadius withTintColor:self.ambientColor];
UIImage *backgroundImageHighlighted = [cuttedImage drn_boxblurImageWithBlur:blurRadius withTintColor:[UIColor colorWithWhite:0.5 alpha:0.5]];
- [obj setBackgroundImage:backgroundImageNormal forState:UIControlStateNormal];
- [obj setBackgroundImage:backgroundImageHighlighted forState:UIControlStateHighlighted];
- obj.backgroundColor = [UIColor clearColor];
+ dispatch_async(dispatch_get_main_queue(), ^{
+ [obj setBackgroundImage:backgroundImageNormal forState:UIControlStateNormal];
+ [obj setBackgroundImage:backgroundImageHighlighted forState:UIControlStateHighlighted];
+ obj.backgroundColor = [UIColor clearColor];
+ });
};
[self.blurBlocks addObject:blurBlock];
useBoxBlurEffect = YES;
@@ -613,15 +620,20 @@ - (void)setupStyle
if (useBoxBlurEffect) {
// 性能问题,暂时关闭
-// self.displayLink.paused = NO;
+// [self.timer fire];
}
}
- (void)refreshBlurEffect
{
- for (void (^blurBlock)() in self.blurBlocks) {
- blurBlock();
- }
+ CGFloat containerHeight = self.actionContainer.bounds.size.height;
+
+ self.originalBackgroundImage = [self screenShotRect:CGRectMake(kContainerLeft, kScreenHeight-containerHeight, self.sheetWidth, containerHeight)];
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
+ for (void (^blurBlock)() in self.blurBlocks) {
+ blurBlock();
+ }
+ });
}
- (void)setupContainerFrame
@@ -633,13 +645,14 @@ - (void)setupContainerFrame
*/
- (void)show
{
+// [self.timer invalidate];
+// self.timer = nil;
+// self.timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(refreshBlurEffect) userInfo:nil repeats:YES];
+
if ([self.delegate respondsToSelector:@selector(willPresentAlertView:)]) {
[self.delegate willPresentActionSheet:self];
}
- self.displayLink.paused = YES;
- [self.displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
-
[self setupNewWindow];
[self setupLayout];
@@ -683,6 +696,9 @@ - (void)showInView:(UIView *)view
*/
- (void)buttonTapped:(TBActionButton *)sender
{
+// [self.timer invalidate];
+// self.timer = nil;
+
if (![self isVisible]) {
return;
}
@@ -724,12 +740,13 @@ - (void)buttonTapped:(TBActionButton *)sender
*/
- (void)close
{
+// [self.timer invalidate];
+// self.timer = nil;
+
if (![self isVisible]) {
return;
}
- [self.displayLink invalidate];
-
[UIView animateWithDuration:self.animationDuration delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
self.background.backgroundColor = [UIColor colorWithWhite:0 alpha:0];
self.actionContainer.frame = CGRectMake(kContainerLeft, kScreenHeight, self.actionContainer.frame.size.width, self.actionContainer.frame.size.height);

0 comments on commit 6bdf479

Please sign in to comment.