IOS7 style pop-up box-supports block callback and ios7block

Source: Internet
Author: User

IOS7 style pop-up box-supports block callback and ios7block

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 <Foundation/Foundation.h>@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 () <comment> @ property (nonatomic, strong) Comment * comment; @ 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 isDisplaying; // The limit cannot be repeated. @ end @ implementation SYTipView + (SYTipView *) specify instance {static dispatch_once_t oneceToken; dispatch_once (& oneceToken, ^ {syTipView = [[self class] alloc] init] ;}); return syT IpView;}-(id) init {self = [super init]; if (self) {UIWindow * keyWindow = GetKeyWindow; if (_ tipViewController = nil) {_ tipViewController = [[UIViewController alloc] init]; [_ tipViewController. view setFrame: CGRectMake (0, 0, TIPVIEW_WIDTH, TIPVIEW_WIDTH)]; _ tipViewController. view. center = CGPointMake (keyWindow. rootViewController. view. bounds. size. width * 0.5f, keyWindow. rootViewController. view. bo Unds. size. height * 0.5f); _ tipViewController. view. autoresizingMask = California | California;} if (_ activityIndicatorView = nil) {_ activityIndicatorView = [[financialloc] initWithFrame: CGRectMake (0, 0, TIPVIEW_WIDTH, TIPVIEW_WIDTH)]; _ activityIndi CatorView. activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray; _ activityIndicatorView. backgroundColor = [UIColor grayColor]; _ activityIndicatorView. alpha = 0.5; _ activityIndicatorView. layer. cornerRadius = 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: im AgePath]; // 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 (_ tipViewC Ontroller. 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] initWithIm Age: [UIImage imageWithContentsOfFile: imagePath]; [_ wrongImageView setFrame: CGRectMake (0, 0, TIPIMAGEVIEW_WIDTH, 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 allo C] initWithFrame: CGRectMake (0, 0, TIPVIEW_WIDTH, TIPVIEW_WIDTH)]; // align 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 ad DSubview: _ 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 correct information prompt //-(void) dismissTipView // {/[_ activity IndicatorView stopAnimating]; // [_ activityIndicatorView removeFromSuperview]; // [_ tipTextView removeFromSuperview]; // [_ tipViewController. view removeFromSuperview]; //} # pragma mark-display the correct information prompt-(void) showSuccessTipWithText :( NSString *) tipText {if (_ isDisplaying) {return;} _ isDisplaying = YES; UIWindow * keyWindow = GetKeyWindow; _ tipViewController. view. center = CGPointMake (keyWindow. rootViewControl Ler. view. bounds. size. width * 0.5f, keyWindow. rootViewController. view. bounds. size. height * 0.5f); [_ tipBgView addSubview: _ rightImageView]; [self createTipTextView: tipText]; [_ tipBgView addSubview: _ tipTextView]; [_ tipViewController. view addSubview: _ tipBgView]; [keyWindow. rootViewController. view addSubview: _ tipViewController. view]; [self initialize mselector: @ selector (removeSuccessTipView) withObject: nil AfterDelay: 1];}-(void) callback {[_ partition removeFromSuperview]; [_ tipTextView Preview]; _ tipTextView = nil; [_ tipBgView removeFromSuperview]; [_ tipViewController. view removeFromSuperview]; _ 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: _ wrongImageView]; [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. bounds. size. height * 0.5f); [_ tipViewController. view addSubview: _ activityIndicatorView]; [self createTipTextView: tipText]; [_ tipViewController. view addSubview: _ tipTextView]; [keyWindow. rootViewControll Er. view addSubview: _ tipViewController. view]; [_ activityIndicatorView startAnimating];} # pragma mark-success prompt for disabling callback-(void) dismissSuccessWithText :( NSString *) tipText block :( void (^ )()) action {[_ Your stopAnimating]; [_ Your removeFromSuperview]; [_ tipBgView addSubview: _ blank]; [_ tipTextView details]; _ tipTextView = nil; [self createTipTextView: tipTex T]; [_ tipBgView addSubview: _ tipTextView]; [_ tipViewController. view addSubview: _ tipBgView]; [self initialize mselector: @ selector (removeSuccessTipViewAction :) withObject: action afterDelay: 1];}-(void) Forward :( void (^ )()) action {[_ tipTextView removeFromSuperview]; _ tipTextView = nil; [_ rightImageView removeFromSuperview]; [_ tipBgView removeFromSuperview]; [_ tipViewController. view remotesoft RomSuperview]; action (); _ isDisplaying = NO;} # pragma mark-failure prompt for disabling callback-(void) dismissErrorWithText :( NSString *) tipText block :( void (^) () action {[_ javasstopanimating]; [_ javasremovefromsuperview]; [_ tipBgView addSubview: _ wrongImageView]; [_ tipTextView removeFromSuperview]; _ 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 {[_ tipTextView removeFromSuperview]; _ tipTextView = nil; [_ wrongImageView removeFromSuperview]; [_ tipBgView removeFromSuperview]; [_ tipViewController. view removeFromSuperview]; action (); _ isDisplaying = NO ;}// -(Void) dismissTipViewAction :( void (^) () action // {// [_ activityIndicatorView stopAnimating]; // [_ activityIndicatorView removeFromSuperview]; // [_ tipTextView removeFromSuperview]; // [_ tipViewController. view removeFromSuperview]; // action (); //} //-(void) dismissWithText :( NSString *) tipText block :( void (^ )()) action/{// _ tipTextView. text = tipText; // [self defined mselector: @ selector (dismissTipViewActi On :) withObject: action afterDelay: 1]; //} # pragma mark-align text vertically or align KVC-(void) observeValueForKeyPath :( NSString *) keyPath ofObject :( id) object change :( NSDictionary *) change context :( void *) context {UITextView * tempTextView = object; // vertically center alignment // 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.