- (instancetype)init
{
self = [super init];
if (self) {
self.windowLevel = UIWindowLevelAlert;
self.frame = [UIScreen mainScreen].bounds;
}
return self;
}
上面设置为警告框类型的
//
// CustomAlertView.m
// 太平人寿项目
//
// Created by lanqs on 15/2/6.
// Copyright (c) 2015年 Tanqihong. All rights reserved.
//
#import "CustomAlertView.h"
@interface CustomAlertView () {
UIView *view;
CGPoint _point;
NSTimer *_timer;
}
@end
@implementation CustomAlertView
- (instancetype)init
{
self = [super init];
if (self) {
self.windowLevel = UIWindowLevelAlert;
self.frame = [UIScreen mainScreen].bounds;
}
return self;
}
- (void)show:(NSString *)string {
UIView *backGroundView = [[UIView alloc]initWithFrame:self.bounds];
backGroundView.backgroundColor = [UIColor blackColor];
backGroundView.alpha = 0.3;
[self addSubview:backGroundView];
view = [[UIView alloc]init];
view.bounds = CGRectMake(0, 0,CGRectGetWidth(self.bounds) * 0.6, CGRectGetWidth(self.bounds) * 0.2);
view.layer.cornerRadius = 10;
view.clipsToBounds = YES;
view.backgroundColor = [UIColor whiteColor];
view.center = CGPointMake(CGRectGetWidth(self.bounds)/2, CGRectGetHeight(self.bounds)/2);
_point = view.center;
[self addSubview:view];
UILabel *lable = [[UILabel alloc]init];
lable.bounds = CGRectMake(0, 0, CGRectGetWidth(view.bounds) - 40, 30);
lable.center = CGPointMake(CGRectGetWidth(view.bounds)/2, CGRectGetHeight(view.bounds)/2);
lable.textColor = [UIColor grayColor];
lable.textAlignment = NSTextAlignmentCenter;
lable.text = string;
[view addSubview:lable];
_timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(viewAnimation) userInfo:nil repeats:YES];
// _timer.fireDate = [NSDate distantFuture];
[self makeKeyAndVisible];
}
- (void)viewAnimation {
// _timer.fireDate = [NSDate dateWithTimeIntervalSinceNow:0];
[UIView animateWithDuration:0.5 animations:^{
view.center = CGPointMake(_point.x, _point.y + 10);
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.5 animations:^{
view.center = CGPointMake(_point.x, _point.y);
}];
}];
}
- (void)hidenView {
[UIView animateWithDuration:0.5 animations:^{
self.alpha = 0.3;
}];
[self performSelector:@selector(timer) withObject:self afterDelay:0.5];
}
- (void)timer {
self.hidden = YES;
_timer.fireDate = [NSDate distantFuture];
}
- (void)showstart {
self.hidden = NO;
_timer.fireDate = [NSDate dateWithTimeIntervalSinceNow:0];
}
@end
调用:
@property (nonatomic,strong)CustomAlertView * window;
_window = [[CustomAlertView alloc] init];
[_window show:@"请等待..."];
记着隐藏
[_window hidenView];
效果图: