181 lines
7.1 KiB
Objective-C
Executable File
181 lines
7.1 KiB
Objective-C
Executable File
//
|
|
// HelpPageDefine.m
|
|
// LiveChat
|
|
//
|
|
// Created by 码农教育6 on 2018/10/22.
|
|
// Copyright © 2018年 manongjiaoyu. All rights reserved.
|
|
//
|
|
|
|
#import "HelpPageDefine.h"
|
|
|
|
//屏幕适配比例
|
|
#define CURRENT_SIZE(size) (size)
|
|
|
|
@interface HelpPageDefine ()<CAAnimationDelegate>
|
|
|
|
@property (nonatomic, strong)UIActivityIndicatorView *activityIndicator;
|
|
@property (nonatomic, strong)UIView *backgroundView;
|
|
@property (nonatomic, strong)UIView *bottomView;
|
|
@property (nonatomic, strong)UIImageView *imageLoading;
|
|
|
|
@end
|
|
|
|
@implementation HelpPageDefine
|
|
|
|
+(void)showMessage:(NSString *)message
|
|
{
|
|
if (message == nil) {
|
|
message = @"";
|
|
}
|
|
CGSize screenSize = [[UIScreen mainScreen] bounds].size;
|
|
|
|
UIWindow * window = [UIApplication sharedApplication].keyWindow;
|
|
UIView *showview = [[UIView alloc]init];
|
|
showview.backgroundColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.75];
|
|
showview.frame = CGRectMake(1, 1, 1, 1);
|
|
showview.layer.cornerRadius = 8.0f;
|
|
showview.layer.masksToBounds = YES;
|
|
[window addSubview:showview];
|
|
|
|
UILabel *label = [[UILabel alloc]init];
|
|
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
|
|
paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;
|
|
|
|
NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:CURRENT_SIZE(15)],
|
|
NSParagraphStyleAttributeName:paragraphStyle.copy};
|
|
|
|
CGSize labelSize = [message boundingRectWithSize:CGSizeMake(ScreenWidth-CURRENT_SIZE(100), 999)
|
|
options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
|
|
attributes:attributes context:nil].size;
|
|
CGFloat labelWidth = ceilf(labelSize.width);
|
|
CGFloat labelHeight = ceilf(labelSize.height);
|
|
|
|
label.text = message;
|
|
label.numberOfLines = 0;
|
|
label.textColor = [UIColor whiteColor];
|
|
label.textAlignment = NSTextAlignmentCenter;
|
|
label.backgroundColor = [UIColor clearColor];
|
|
label.font = [UIFont systemFontOfSize:CURRENT_SIZE(15)];
|
|
[showview addSubview:label];
|
|
|
|
showview.frame = CGRectMake((screenSize.width - labelWidth)/2-CURRENT_SIZE(50)/2,
|
|
(screenSize.height - (labelHeight+CURRENT_SIZE(20)))/2,
|
|
labelWidth+CURRENT_SIZE(50),
|
|
labelHeight+CURRENT_SIZE(20));
|
|
label.center = CGPointMake(showview.frame.size.width/2, showview.frame.size.height/2);
|
|
label.bounds = CGRectMake(0, 0, labelWidth, labelHeight);
|
|
[UIView animateWithDuration:1.5f animations:^{
|
|
showview.alpha = 0;
|
|
} completion:^(BOOL finished) {
|
|
[showview removeFromSuperview];
|
|
}];
|
|
}
|
|
|
|
+(void)showMessage:(NSString *)message duration:(double)time
|
|
{
|
|
if (message == nil) {
|
|
message = @"";
|
|
}
|
|
CGSize screenSize = [[UIScreen mainScreen] bounds].size;
|
|
|
|
UIWindow * window = [UIApplication sharedApplication].keyWindow;
|
|
UIView *showview = [[UIView alloc]init];
|
|
showview.backgroundColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.75];
|
|
showview.frame = CGRectMake(1, 1, 1, 1);
|
|
showview.layer.cornerRadius = 8.0f;
|
|
showview.layer.masksToBounds = YES;
|
|
[window addSubview:showview];
|
|
|
|
UILabel *label = [[UILabel alloc]init];
|
|
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
|
|
paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;
|
|
|
|
NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:CURRENT_SIZE(15)],
|
|
NSParagraphStyleAttributeName:paragraphStyle.copy};
|
|
|
|
CGSize labelSize = [message boundingRectWithSize:CGSizeMake(ScreenWidth-CURRENT_SIZE(100), 999)
|
|
options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
|
|
attributes:attributes context:nil].size;
|
|
CGFloat labelWidth = ceilf(labelSize.width);
|
|
CGFloat labelHeight = ceilf(labelSize.height);
|
|
|
|
label.text = message;
|
|
label.numberOfLines = 0;
|
|
label.textColor = [UIColor whiteColor];
|
|
label.textAlignment = NSTextAlignmentCenter;
|
|
label.backgroundColor = [UIColor clearColor];
|
|
label.font = [UIFont systemFontOfSize:CURRENT_SIZE(15)];
|
|
[showview addSubview:label];
|
|
|
|
showview.frame = CGRectMake((screenSize.width - labelWidth)/2-CURRENT_SIZE(50)/2,
|
|
(screenSize.height - (labelHeight+CURRENT_SIZE(20)))/2,
|
|
labelWidth+CURRENT_SIZE(50),
|
|
labelHeight+CURRENT_SIZE(20));
|
|
label.center = CGPointMake(showview.frame.size.width/2, showview.frame.size.height/2);
|
|
label.bounds = CGRectMake(0, 0, labelWidth, labelHeight);
|
|
[UIView animateWithDuration:time animations:^{
|
|
showview.alpha = 0;
|
|
} completion:^(BOOL finished) {
|
|
[showview removeFromSuperview];
|
|
}];
|
|
}
|
|
|
|
//菊花刷新
|
|
- (void)creatActivityIndicatorView:(UIView *)subview
|
|
{
|
|
_bottomView = [[UIView alloc] init];
|
|
_bottomView.center = CGPointMake(ScreenWidth/2, ScreenHeight/2);
|
|
_bottomView.bounds = CGRectMake(0, 0, ScreenWidth, ScreenHeight);
|
|
_bottomView.backgroundColor = [UIColor blackColor];
|
|
_bottomView.alpha = 0.3;
|
|
[subview addSubview:_bottomView];
|
|
|
|
_backgroundView = [[UIView alloc] init];
|
|
_backgroundView.center = CGPointMake(ScreenWidth/2, ScreenHeight/2);
|
|
_backgroundView.bounds = CGRectMake(0, 0, 100, 100);
|
|
_backgroundView.backgroundColor = [UIColor blackColor];
|
|
_backgroundView.layer.masksToBounds = YES;
|
|
_backgroundView.layer.cornerRadius = 5;
|
|
//_backgroundView.alpha = 0.8;
|
|
[_bottomView addSubview:_backgroundView];
|
|
|
|
_activityIndicator = [[UIActivityIndicatorView alloc] init];
|
|
_activityIndicator.center =CGPointMake(_backgroundView.frame.size.width/2, _backgroundView.frame.size.height/2);
|
|
_activityIndicator.bounds = CGRectMake(0, 0, 40, 40);
|
|
_activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
|
|
_activityIndicator.hidesWhenStopped = YES;
|
|
[_backgroundView addSubview:_activityIndicator];
|
|
[_activityIndicator startAnimating];
|
|
}
|
|
|
|
-(CABasicAnimation *)rotation:(float)dur direction:(int)direction repeatCount:(int)repeatCount
|
|
{
|
|
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
|
|
animation.toValue = [NSNumber numberWithFloat:M_PI * 2.0];
|
|
animation.duration = dur;
|
|
animation.autoreverses = NO;
|
|
animation.cumulative = YES;
|
|
animation.fillMode = kCAFillModeForwards;
|
|
animation.repeatCount = repeatCount;
|
|
animation.removedOnCompletion = NO;
|
|
animation.fillMode = kCAFillModeForwards;
|
|
animation.delegate = self;
|
|
|
|
return animation;
|
|
|
|
}
|
|
- (void)stopImageLoading{
|
|
[_imageLoading stopAnimating];
|
|
[_imageLoading removeFromSuperview];
|
|
}
|
|
|
|
- (void)stopActivityIndicatorView{
|
|
if ([_activityIndicator isAnimating]) {
|
|
[_activityIndicator stopAnimating];
|
|
}
|
|
[_backgroundView removeFromSuperview];
|
|
[_bottomView removeFromSuperview];
|
|
}
|
|
|
|
@end
|