IOS7 style pop-up box-block callback supported

Source: Internet
Author: User

IOS7 style pop-up box-block callback supported

I haven't updated my blog for a long time. I wrote a pop-up box today, which is mainly used in the SDK.

Post it to share it:

#import 
 
  @interface SYTipView : NSObject+ (SYTipView *)shareInstance;- (void)showSuccessTipWithText:(NSString *)tipText;- (void)showErrorTipWithText:(NSString *)tipText;- (void)startWithText:(NSString *)tipText;- (void)dismissSuccessWithText:(NSString *)tipText block:(void(^)())action;- (void)dismissErrorWithText:(NSString *)tipText block:(void(^)())action;@end
 

# Import "SYTipView. h" # define KEYWINDOW [UIApplication sharedApplication]. keyWindow # define GetKeyWindow KEYWINDOW? KEYWINDOW: [[UIApplication sharedApplication]. windows objectAtIndex: 0] # define TIPVIEW_WIDTH 100 # define TIPIMAGEVIEW_WIDTH 30 static SYTipView * syTipView = nil; @ interface SYTipView ()
 
  
@ Property (nonatomic, strong) Comment * activityIndicatorView; @ property (nonatomic, strong) UITextView * tipTextView; @ property (nonatomic, strong) UIViewController * tipViewController; @ property (nonatomic, strong) UIView * tipBgView; @ property (nonatomic, strong) UIImageView * rightImageView; @ property (nonatomic, strong) UIImageView * wrongImageView; @ property (nonatomic, assign) BOOL isDis Playing; // The limit cannot be repeated. @ end @ implementation SYTipView + (SYTipView *) Duplicate instance {static dispatch_once_t oneceToken; dispatch_once (& oneceToken, ^ {syTipView = [[self class] alloc] init] ;}); return syTipView ;}- (id) init {self = [super init]; if (self) {UIWindow * keyWindow = GetKeyWindow; if (_ tipViewController = nil) {_ tipViewController = [[UIViewController alloc] init]; [_ tipViewController. view se TFrame: CGRectMake (0, 0, TIPVIEW_WIDTH, TIPVIEW_WIDTH)]; _ tipViewController. view. center = CGPointMake (keyWindow. rootViewController. view. bounds. size. width * 0.5f, keyWindow. rootViewController. view. bounds. size. height * 0.5f); _ tipViewController. view. autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizin Dependencies;} if (_ activityIndicatorView = nil) {_ activityIndicatorView = [[externalloc] initWithFrame: CGRectMake (0, 0, TIPVIEW_WIDTH, TIPVIEW_WIDTH)]; _ bytes. activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray; _ activityIndicatorView. backgroundColor = [UIColor grayColor]; _ activityIndicatorView. alpha = 0.5; _ activityIndicatorView. layer. cor NerRadius = 10;} if (_ tipBgView = nil) {_ tipBgView = [[UIView alloc] initWithFrame: CGRectMake (0, 0, TIPVIEW_WIDTH, TIPVIEW_WIDTH)]; _ tipBgView. layer. cornerRadius = 10; _ tipBgView. backgroundColor = [UIColor grayColor]; _ tipBgView. alpha = 0.5;} if (_ rightImageView = nil) {NSString * bundlePath = [[NSBundle mainBundle] pathForResource: @ "SYTipView" ofType: @ "bundle"]; NSBundle * bundle = [NSBundle BundleWithPath: bundlePath]; NSString * imagePath = [bundle pathForResource: @ "images/SY_arrow" ofType: @ "png"]; _ rightImageView = [[UIImageView alloc] initWithImage: [UIImage imageWithContentsOfFile: imagePath]; // NSString * const MJRefreshBundleName = @ "SYTipView. bundle "; // NSString * path = [MJRefreshBundleName stringByAppendingPathComponent: @" images/SY_arrow.png "]; // UIImage * a = [UIImage imageNamed: Path]; // _ rightImageView = [[UIImageView alloc] initWithImage: a]; [_ blank setFrame: CGRectMake (0, 0, TIPIMAGEVIEW_WIDTH, TIPIMAGEVIEW_WIDTH)]; _ rightImageView. center = CGPointMake (_ tipViewController. view. bounds. size. width/2, _ tipViewController. view. bounds. size. height-64);} if (_ wrongImageView = nil) {NSString * bundlePath = [[NSBundle mainBundle] pathForResource: @ "SYTipView" ofType :@" Bundle "]; NSBundle * bundle = [NSBundle bundleWithPath: bundlePath]; NSString * imagePath = [bundle pathForResource: @" images/SY_wrong "ofType: @" png "]; _ wrongImageView = [[UIImageView alloc] initWithImage: [UIImage preview: imagePath]; [_ wrongImageView setFrame: CGRectMake (0, 0, partial, TIPIMAGEVIEW_WIDTH)]; _ wrongImageView. center = CGPointMake (_ tipViewController. view. bounds. Size. width/2, _ tipViewController. view. bounds. size. height-64) ;}} return self ;}# pragma mark-construct TipTextView-(void) createTipTextView :( NSString *) tipText {// text prompt _ tipTextView = [[UITextView alloc] initWithFrame: CGRectMake (0, 0, TIPVIEW_WIDTH, TIPVIEW_WIDTH)]; // align the text vertically _ tipTextView. delegate = self; [_ tipTextView addObserver: self forKeyPath: @ "contentSize" options :( NSKeyValueObservingOptionNew) Context: nil]; _ tipTextView. textAlignment = NSTextAlignmentCenter; _ tipTextView. font = [UIFont boldSystemFontOfSize: 14]; _ tipTextView. backgroundColor = [UIColor clearColor]; _ tipTextView. textColor = [UIColor whiteColor]; _ tipTextView. userInteractionEnabled = NO; _ tipTextView. text = tipText;} // # pragma mark-//-(void) showTipWithText :( NSString *) tipText // {// UIWindow * keyWindow = GetKeyWindow ;//// _ TipViewController. view. center = CGPointMake (keyWindow. rootViewController. view. bounds. size. width * 0.5f, keyWindow. rootViewController. view. bounds. size. height * 0.5f); // [_ tipViewController. view addSubview: _ activityIndicatorView]; // [self createTipTextView: tipText]; // [_ tipViewController. view addSubview: _ tipTextView]; // [keyWindow. rootViewController. view addSubview: _ tipViewController. view];/ /// [_ ActivityIndicatorView startAnimating]; // [self defined mselector: @ selector (dismissTipView) withObject: nil afterDelay: 1]; ///} // # pragma mark-display the correct information prompt //-(void) dismissTipView // {// [_ activityIndicatorView stopAnimating]; // [_ activityIndicatorView removeFromSuperview]; // [_ tipTextView removeFromSuperview]; // [_ tipViewController. view removeFromSuperview]; //} # pragma mark-display correct information prompt-(void) showS UccessTipWithText :( NSString *) tipText {if (_ isDisplaying) {return;} _ isDisplaying = YES; UIWindow * keyWindow = GetKeyWindow; _ tipViewController. view. center = CGPointMake (keyWindow. rootViewController. view. bounds. size. width * 0.5f, keyWindow. rootViewController. view. bounds. size. height * 0.5f); [_ tipBgView addSubview: _ rightImageView]; [self createTipTextView: tipText]; [_ tipBgView addSubview: _ tipText View]; [_ tipViewController. view addSubview: _ tipBgView]; [keyWindow. rootViewController. view addSubview: _ tipViewController. view]; [self defined mselector: @ selector (optional) withObject: nil afterDelay: 1];}-(void) Comment {[_ rightImageView removeFromSuperview]; [_ tipTextView removeFromSuperview]; _ tipTextView = nil; [_ tipBgView removeFromSuperview]; [_ tipViewController. view remo VeFromSuperview]; _ isDisplaying = NO;} # pragma mark-Display error message-(void) showErrorTipWithText :( NSString *) tipText {if (_ isDisplaying) {return ;} _ isDisplaying = YES; UIWindow * keyWindow = GetKeyWindow; _ tipViewController. view. center = CGPointMake (keyWindow. rootViewController. view. bounds. size. width * 0.5f, keyWindow. rootViewController. view. bounds. size. height * 0.5f); [_ tipBgView addSubview: _ wrongImage View]; [self createTipTextView: tipText]; [_ tipBgView addSubview: _ tipTextView]; [_ tipViewController. view addSubview: _ tipBgView]; [keyWindow. rootViewController. view addSubview: _ tipViewController. view]; [self defined mselector: @ selector (optional) withObject: nil afterDelay: 1];}-(void) Comment {[_ wrongImageView removeFromSuperview]; [_ tipTextView removeFromSuperview]; _ tipTextView = Nil; [_ tipBgView removeFromSuperview]; [_ tipViewController. view removeFromSuperview]; _ isDisplaying = NO;} # pragma mark-start prompt-(void) startWithText :( NSString *) tipText; {if (_ isDisplaying) {return ;} _ isDisplaying = YES; UIWindow * keyWindow = GetKeyWindow; _ tipViewController. view. center = CGPointMake (keyWindow. rootViewController. view. bounds. size. width * 0.5f, keyWindow. rootViewController. view. boun Ds. size. height * 0.5f); [_ tipViewController. view addSubview: _ activityIndicatorView]; [self createTipTextView: tipText]; [_ tipViewController. view addSubview: _ tipTextView]; [keyWindow. rootViewController. view addSubview: _ tipViewController. view]; [_ activityIndicatorView startAnimating];} # pragma mark-success prompt for disabling callback-(void) dismissSuccessWithText :( NSString *) tipText block :( void (^ )()) action {[_ activityIndica TorView stopAnimating]; [_ incluremovefromsuperview]; [_ tipBgView addSubview: _ blank]; [_ tipTextView removeFromSuperview]; _ tipTextView = nil; [self createTipTextView: tipText] [_ tipBgView addSubview: _ tipTextView]; [_ tipViewController. view addSubview: _ tipBgView]; [self initialize mselector: @ selector (removeSuccessTipViewAction :) withObject: action afterDelay: 1];}-(void) removeSucc EssTipViewAction :( void (^) () action {[_ tipTextView removeFromSuperview]; _ tipTextView = nil; [_ blank removeFromSuperview]; [_ tipBgView Preview]; [_ tipViewController. view removeFromSuperview]; action (); _ isDisplaying = NO;} # pragma mark-failure prompt for disabling callback-(void) dismissErrorWithText :( NSString *) tipText block :( void (^) () action {[_ activityIndicatorView stopAnimating]; [_ activityIndicator View Details]; [_ tipBgView addSubview: _ blank]; [_ tipTextView details]; _ tipTextView = nil; [self createTipTextView: tipText]; [_ tipBgView addSubview: _ tipTextView]; [_ tipViewController. view addSubview: _ tipBgView]; [self initialize mselector: @ selector (removeErrorTipViewAction :) withObject: action afterDelay: 1];}-(void) removeErrorTipViewAction :( void (^ )()) action {[_ tipTextVi Ew removeFromSuperview]; _ tipTextView = nil; [_ wrongImageView removeFromSuperview]; [_ tipBgView removeFromSuperview]; [_ tipViewController. view removeFromSuperview]; action (); _ isDisplaying = NO;} //-(void) dismissTipViewAction :( void (^ )()) action // {// [_ activityIndicatorView stopAnimating]; // [_ activityIndicatorView removeFromSuperview]; // [_ tipTextView removeFromSuperview]; // [_ tipViewController. vie W removeFromSuperview]; // action (); //} //-(void) dismissWithText :( NSString *) tipText block :( void (^ )()) action/{// _ tipTextView. text = tipText; // [self defined mselector: @ selector (dismissTipViewAction :) withObject: action afterDelay: 1]; //} # pragma mark-align the text vertically or align the bottom center KVC-(void) observeValueForKeyPath :( NSString *) keyPath ofObject :( id) object change :( NSDictionary *) change context :( void *) context {UITe XtView * tempTextView = object; // align vertically in the center // CGFloat topCorrect = (tempTextView. bounds. size. height-tempTextView. contentSize. height * tempTextView. zoomScale)/2; // topCorrect = topCorrect <0.0? 0.0: topCorrect; // tempTextView. contentOffset = (CGPoint ){. x = 0 ,. y =-topCorrect}; // Bottom vertical alignment CGFloat topCorrect = ([tempTextView bounds]. size. height-[tempTextView contentSize]. height); topCorrect = (topCorrect <0.0? 0.0: topCorrect); tempTextView. contentOffset = (CGPoint ){. x = 0 ,. y =-topCorrect}; [tempTextView removeObserver: self forKeyPath: @ "contentSize" context: nil];} @ 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.