IOS _ 3rd library _ BlurAlertView_GPUImage

Source: Internet
Author: User

IOS _ 3rd library _ BlurAlertView_GPUImage
Finally:

Add GPUImage. framework first








Class description and class implementation for importing BlurAlertView

//// BlurAlertView. h // special effect pop-up box /// Created by beyond on 14-10-18. // Copyright (c) 2014 com. beyond All rights reserved. // # import
 
  
// You must first import GPUImage. framework # import
  
   
@ Class BlurAlertView; @ protocol identifier; typedef NS_ENUM (NSInteger, identifier) {identifier, identifier}; typedef NS_ENUM (NSInteger, BlurAlertViewContentType) {identifier, identifier}; @ interface BlurAlertView: UIView @ property (nonatomic, strong) UIButton * okButton; @ property (nonatomic, strong) UIButton * cancelButton; @ property (nonatomic, assign) implements animationType; @ property (nonatomic, weak) id
   
    
Delegate; @ property (nonatomic, copy) void (^ completionBlock) (BlurAlertView * alertView, UIButton * button);-(id) initWithTitle :( NSString *) title text :( NSString *) text cancelButton :( BOOL) hasCancelButton;-(id) initWithTitle :( NSString *) title contentView :( UIView *) contentView cancelButton :( BOOL) hasCancelButton;-(void) show;-(void) dismiss; @ end @ protocol BlurAlertViewDelegate
    
     
@ Optional-(void) alertView :( BlurAlertView *) alertView preview :( UIButton *) button;-(void) preview :( optional *) alertView;-(void) skip :( BlurAlertView *) alertView;-(void) alertViewWillDismiss :( BlurAlertView *) alertView;-(void) alertViewDidDismiss :( BlurAlertView *) alertView; @ end // grand introduction/************************ Title and Text: BlurAlertView * alertView = [BlurAlert View alloc] initWithTitle: @ "title" text: @ "this is text" cancelButton: YES color: [UIColor blueColor]; // set animation type alertView. animationType = bluralertviewanimationtypeddrop; [alertView setCompletionBlock: ^ (BlurAlertView * alert, UIButton * button) {if (button = alert. okButton) {NSLog (@ "OK button touched! ");} Else {NSLog (@" cancel button touched! ") ;}}]; [AlertView show]; * // ***************** Custom content view: UIView * contentView = [[UIView alloc] initWithFrame: CGRectMake (0, 0,180,180)]; contentView. backgroundColor = [UIColor blackColor]; BlurAlertView * alertView = [[BlurAlertView alloc] initWithTitle: @ "title" contentView: contentView cancelButton: YES color: [UIColor blueColor]; [alertView show]; */
    
   
  
 



//// BlurAlertView. m // special effect pop-up box /// Created by beyond on 14-10-18. // Copyright (c) 2014 com. beyond All rights reserved. // static const float Height = 44.0; static const float AlertViewSpaceHeight = 10; static const float Height = 16;/* Default Colors */# define effectitlelabelbackgroundcolor [UIColor colorWithRed: 0.20392156862745098 green: 0.596078431372549 blue: 0.8588235294117647 alpha: 1.0] # define colors comfirmbuttoncolor [UIColor colorWithRed: 0.20392156862745098 green: 0.596078431372549 blue: 0.8588235294117647 alpha: 1.0] # define screenBounds [[UIScreen mainScreen] bounds] # define IS_IOS7_Or_Later [[[UIDevice currentDevice] systemVersion] floatValue]> = 7.0 # import "BlurAlertView. h "@ interface BlurAlertView () @ property (nonatomic, strong) returns * blurFilter; @ property (nonatomic, strong) UIView * alertView; @ property (nonatomic, strong) UIImageView * backgroundView; @ property (nonatomic, strong) UILabel * titleLabel; @ property (nonatomic, strong) UILabel * textLabel; @ property (nonatomic, assign) CGSize contentSize; @ property (nonatomic, assign) inclucontenttype; @ property (nonatomic, strong) UIView * contentView; @ end @ implementation BlurAlertView-(id) initWithTitle :( NSString *) title contentView :( UIView *) contentView cancelButton :( BOOL) hasCancelButton {self = [super initWithFrame: screenBounds]; if (self) {self. opaque = YES; self. alpha = 1; _ contentType = BlurAlertViewContentTypeCustomView; _ contentView = contentView; [self _ setupViewsWithTitle: title text: nil cancelButton: hasCancelButton];} return self;}-(id) initWithTitle :( NSString *) title text :( NSString *) text cancelButton :( BOOL) hasCancelButton {self = [super initWithFrame: screenBounds]; if (self) {self. opaque = YES; self. alpha = 1; _ contentType = BlurAlertViewContentTypeText; [self _ setupViewsWithTitle: title text: text cancelButton: hasCancelButton];} return self ;}# pragma mark-Show and Dismiss-(void) show {if ([self. delegate respondsToSelector: @ selector (alertViewWillShow :)]) {[self. delegate alertViewWillShow: self];} switch (self. animationType) {case when: [self triggerBounceAnimations]; break; case BlurAlertViewAnimationTypeDrop: [self triggerDropAnimations]; break; default: break ;} [[[UIApplication sharedApplication] delegate] window] addSubview: self];}-(void) dismiss {if ([self. delegate respondsToSelector: @ selector (alertViewWillDismiss :)]) {[self. delegate alertViewWillDismiss: self];} [UIView animateWithDuration: 0.4 delay: 0.0 options: UIViewAnimationOptionCurveEaseInOut animations: ^ {self. alpha = 0;} completion: ^ (BOOL finished) {[self removeFromSuperview]; if ([self. delegate respondsToSelector: @ selector (alertViewDidDismiss :)]) {[self. delegate alertViewDidDismiss: self] ;}}] ;}# pragma mark-Animations-(void) triggerBounceAnimations {self. alertView. alpha = 0; self. alertView. center = CGPointMake (CGRectGetWidth (screenBounds)/2, (CGRectGetHeight (screenBounds)/2); Parameters * animation; animation = [CAKeyframeAnimation attributes: @ "transform"]; animation. duration = 0.3f; // animation. delegate = self; animation. removedOnCompletion = NO; animation. fillMode = modes; NSMutableArray * values = [NSMutableArray array]; [values addObject: [NSValue failed: Average (0.1, 0.1, 1.0)]; [values addObject: [NSValue failed: CATransform3DMakeScale (1.2, 1.2, 1.0)]; [values addObject: [NSValue valueWithCATransform3D: CATransform3DMakeScale (1.0, 1.0, 1.0)]; animation. values = values; animation. timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseInEaseOut]; [self. alertView. layer addAnimation: animation forKey: nil]; [UIView animateWithDuration: 0.3f delay: 0 options: enabled | UIViewAnimationCurveEaseIn | adjust animations :^{ [self. backgroundView setAlpha: 1.0]; [self. alertView setAlpha: 1.0];} completion: ^ (BOOL finished) {if ([self. delegate respondsToSelector: @ selector (alertViewDidShow :)]) {[self. delegate alertViewDidShow: self] ;}}] ;}- (void) implements {CAKeyframeAnimation * animation; animation = [CAKeyframeAnimation animationWithKeyPath: @ "position"]; animation. duration = 0.4f; // animation. delegate = self; animation. removedOnCompletion = NO; animation. fillMode = kCAFillModeForwards; NSMutableArray * values = [NSMutableArray array]; [values addObject: [NSValue valueWithCGPoint: CGPointMake (screenBounds. size. width/2,-self. alertView. frame. size. height)]; [values addObject: [NSValue valueWithCGPoint: CGPointMake (screenBounds. size. width/2, (screenBounds. size. height/2) + self. alertView. frame. size. height * 0.05)]; [values addObject: [NSValue valueWithCGPoint: CGPointMake (screenBounds. size. width/2, (screenBounds. size. height/2)]; [values addObject: [NSValue valueWithCGPoint: CGPointMake (screenBounds. size. width/2, (screenBounds. size. height/2)-self. alertView. frame. size. height * 0.05)]; [values addObject: [NSValue valueWithCGPoint: CGPointMake (screenBounds. size. width/2, (screenBounds. size. height/2)]; animation. values = values; animation. timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseInEaseOut]; [self. alertView. layer addAnimation: animation forKey: nil]; [UIView animateWithDuration: 0.4 delay: 0.0 options: UIViewAnimationOptionCurveEaseOut animations: ^ {self. backgroundView. alpha = 1.0;} completion: ^ (BOOL finished) {if ([self. delegate respondsToSelector: @ selector (alertViewDidShow :)]) {[self. delegate alertViewDidShow: self] ;}}] ;#pragma mark-View Setup-(void) _ setupViewsWithTitle :( NSString *) title text :( NSString *) aText cancelButton :( BOOL) hasCancelButton {[self calculateContentSize: aText];/* setup backgroundView */_ blurFilter = [[GPUImageiOSBlurFilter alloc] init]; _ blurFilter. crop = 2.0; _ backgroundView = [[UIImageView alloc] initWithFrame: screenBounds]; UIImage * image = [self _ convertViewToImage]; UIImage * crop = [_ blurFilter imageByFilteringImage: image]; [self. backgroundView setImage: blurredSnapshotImage]; self. backgroundView. alpha = 0.0; [self addSubview: self. backgroundView];/* setup alertPopupView */self. alertView = [self _ alertPopupView];/* setup title and content view */[self _ labelSetupWithTitle: title andText: aText]; [self addSubview: self. alertView];/* setup buttons */[self _ buttonSetupWithCancelButton: hasCancelButton];}-(void) _ labelSetupWithTitle :( NSString *) title andText :( NSString *) text {_ titleLabel = [[UILabel alloc] initWithFrame: CGRectMake (0, 0,180, AlertViewTitleLabelHeight)]; _ titleLabel. center = CGPointMake (CGRectGetWidth (self. alertView. frame)/2, AlertViewTitleLabelHeight/2); _ titleLabel. text = title; _ titleLabel. font = [UIFont fontWithName: @ "HelveticaNeue-LightItalic" size: 20366f]; _ titleLabel. textAlignment = NSTextAlignmentCenter; [self. alertView addSubview: _ titleLabel]; if (self. contentType = BlurAlertViewContentTypeText) {_ textLabel = [[UILabel alloc] initWithFrame: CGRectMake (0, 0,180, self. contentSize. height)]; _ textLabel. center = CGPointMake (self. alertView. frame. size. width/2, CGRectGetHeight (self. alertView. frame)/2); _ textLabel. text = text; _ textLabel. font = [UIFont fontWithName: @ "HelveticaNeue" size: AlertViewDefaultTextFontSize]; _ textLabel. textAlignment = NSTextAlignmentCenter; _ textLabel. lineBreakMode = NSLineBreakByWordWrapping; _ textLabel. numberOfLines = 0; [self. alertView addSubview: _ textLabel];} else {// customView type self. contentView. center = CGPointMake (self. alertView. frame. size. width/2, CGRectGetHeight (self. alertView. frame)/2); [self. alertView addSubview: self. contentView] ;}}- (UIView *) _ alertPopupView {UIView * alertSquare = [[UIView alloc] initWithFrame: CGRectMake (0, 0,200, rows + 2 * AlertViewSpaceHeight + self. contentSize. height + AlertViewTitleLabelHeight)]; alertSquare. backgroundColor = [UIColor colorWithRed: 0.937 green: 0.937 blue: 0.937 alpha: 1]; alertSquare. center = CGPointMake (CGRectGetWidth (screenBounds)/2, CGRectGetHeight (screenBounds)/2); [alertSquare. layer setCornerRadius: 4.0]; [alertSquare. layer setShadowColor: [UIColor blackColor]. CGColor]; [alertSquare. layer setShadowOpacity: 0.4]; [alertSquare. layer setShadowRadius: 20366f]; [alertSquare. layer setShadowOffset: CGSizeMake (0.0, 0.0)]; // add top background layer CAShapeLayer * topBackgroundLayer = [CAShapeLayer layer]; optional * topBackgroundPath = [commandid: CGRectMake (, 0, CGRectGetWidth (alertSquare. frame), AlertViewTitleLabelHeight) byRoundingCorners: UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii: CGSizeMake (4.0, 4.0)]; topBackgroundLayer. path = topBackgroundPath. CGPath; topBackgroundLayer. fillColor = effectitlelabelbackgroundcolor. CGColor; [alertSquare. layer addSublayer: topBackgroundLayer]; return alertSquare;}-(void) _ buttonSetupWithCancelButton :( BOOL) hasCancelButton {CGFloat buttonCenterY = (CGRectGetHeight (self. alertView. frame) * 2-30-AlertViewSpaceHeight)/2; if (hasCancelButton) {// OK button _ okButton = [[UIButton alloc] initWithFrame: CGRectMake (0, 0, 84, 30)]; _ okButton. center = CGPointMake (CGRectGetWidth (self. alertView. frame)/4) + 3, buttonCenterY); // cancel button _ cancelButton = [[UIButton alloc] initWithFrame: CGRectMake (0, 0, 84, 30)]; _ cancelButton. center = CGPointMake (CGRectGetWidth (self. alertView. frame) * 3/4)-3, buttonCenterY); _ cancelButton. backgroundColor = [UIColor colorWithRed: 0.792 green: 0.792 blue: 0.792 alpha: 1]; [_ cancelButton setTitle: @ "cancel" forState: UIControlStateNormal]; _ cancelButton. titleLabel. textColor = [UIColor whiteColor]; _ cancelButton. titleLabel. font = [UIFont fontWithName: @ "HelveticaNeue" size: 18366f]; [_ cancelButton addTarget: self action: @ selector (handleButtonTouched :) forControlEvents: Handler]; [_ cancelButton. layer setCornerRadius: 3.0f];} else {_ okButton = [[UIButton alloc] initWithFrame: CGRectMake (0, 0,180, 30)]; _ okButton. center = CGPointMake (CGRectGetWidth (self. alertView. frame)/2, buttonCenterY);} [_ okButton setBackgroundColor: Custom comfirmbuttoncolor]; // OK button end setup [_ okButton setTitle: @ "OK" forState: UIControlStateNormal]; _ okButton. titleLabel. font = [UIFont fontWithName: @ "HelveticaNeue" size: 18366f]; [_ okButton addTarget: self action: @ selector (handleButtonTouched :) forControlEvents: Handler]; [_ okButton. layer setCornerRadius: 3.0f]; [self. alertView addSubview: _ okButton]; if (hasCancelButton) {[self. alertView addSubview: _ cancelButton] ;}}- (void) calculateContentSize :( NSString *) text {UIFont * font = [UIFont fontWithName: @ "HelveticaNeue" size: Signature]; CGSize constrainedSize = CGSizeMake (180, CGFLOAT_MAX); if (IS_IOS7_Or_Later) {NSDictionary * tdic = [NSDictionary identifier: font, NSFontAttributeName, nil]; self. contentSize = [text boundingRectWithSize: constrainedSize options: NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes: tdic context: nil]. size;} else {# pragma clang diagnostic push # pragma clang diagnostic ignored "-Wdeprecated-declarations" self. contentSize = [text sizeWithFont: font constrainedToSize: constrainedSize lineBreakMode: NSLineBreakByCharWrapping]; # pragma clang diagnostic pop} if (self. contentType = BlurAlertViewContentTypeCustomView) {self. contentSize = self. contentView. bounds. size }}- (UIImage *) _ convertViewToImage {UIWindow * keyWindow = [[UIApplication sharedApplication] keyWindow]; CGRect rect = [keyWindow bounds]; UIGraphicsBeginImageContextWithOptions (rect. size, YES, 0.0f); CGContextRef context = UIGraphicsGetCurrentContext (); [keyWindow. layer renderInContext: context]; UIImage * capturedScreen = Response (); UIGraphicsEndImageContext (); return capturedScreen;} # pragma mark-Button Action-(void) handleButtonTouched :( UIButton *) button {[self dismiss]; if ([self. delegate respondsToSelector: @ selector (alertView: didDismissWithButton :)]) {[self. delegate alertView: self didDismissWithButton: button];} if (self. completionBlock) {self. completionBlock (self, button) ;}}@ end



Master controller, Example

//// ViewController. m // special effect pop-up box /// Created by beyond on 14-10-18. // Copyright (c) 2014 com. beyond All rights reserved. // # import "ViewController. h "// 1 import # import" BlurAlertView. h "@ interface ViewController () @ end @ implementation ViewController-(void) viewDidLoad {[super viewDidLoad]; // Add image CGRect rect = CGRectMake (0, 20,320,460 ); UIImageView * imageView = [[UIImageView alloc] initWithFrame: rect]; im AgeView. image = [UIImage imageNamed: @ "1.png"]; imageView. contentMode = UIViewContentModeScaleAspectFill; [self. view addSubview: imageView]; // Add button UIButton * btn = [UIButton buttonWithType: UIButtonTypeContactAdd]; btn. frame = CGRectMake (0, 40, 40, 40); [btn addTarget: self action: @ selector (showAlertView) forControlEvents: UIControlEventTouchUpInside]; [self. view addSubview: btn]; // Add button 2 UIButton * bt N2 = [UIButton buttonWithType: Custom]; btn2.frame = CGRectMake (0, 80, 40, 40); [btn2 addTarget: self action: @ selector (showAlertView2) forControlEvents: Listener]; [self. view addSubview: btn2] ;}# pragma mark-3rd side Alert Control-(void) showAlertView {BlurAlertView * alertView = [[BlurAlertView alloc] initWithTitle: @ "title" text: @ "text" cancelButton: YES]; // sets the CA animation type alertView. anim AtionType = BlurAlertViewAnimationTypeBounce; // bluralertviewanimationtypeddrop; [alertView setCompletionBlock: ^ (BlurAlertView * alert, UIButton * button) {if (button = alert. okButton) {NSLog (@ "OK button touched! ");} Else {NSLog (@" cancel button touched! ") ;}}]; [AlertView show];}-(void) showAlertView2 {BlurAlertView * alertView = [[BlurAlertView alloc] initWithTitle: @" title "text: @ "text" cancelButton: YES]; // sets the CA animation type // alertView. animationType = BlurAlertViewAnimationTypeBounce; alertView. animationType = bluralertviewanimationtypeddrop; [alertView setCompletionBlock: ^ (BlurAlertView * alert, UIButton * button) {if (button = alert. okButton) {NSLog (@ "OK button touched! ");} Else {NSLog (@" cancel button touched! ") ;}}]; [AlertView show] ;}@ end























Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.