115 lines
3.8 KiB
Objective-C
115 lines
3.8 KiB
Objective-C
//
|
|
// ZcqVender.m
|
|
// TreeHole
|
|
//
|
|
// Created by 郑创权 on 2022/10/7.
|
|
//
|
|
|
|
#import "ZcqVender.h"
|
|
|
|
@implementation ZcqVender
|
|
|
|
+ (UIViewController *)theTopviewControler{
|
|
//获取根控制器
|
|
UIViewController *rootVC = [[UIApplication sharedApplication].delegate window].rootViewController;
|
|
|
|
UIViewController *parent = rootVC;
|
|
//遍历 如果是presentViewController
|
|
while ((parent = rootVC.presentedViewController) != nil ) {
|
|
rootVC = parent;
|
|
}
|
|
|
|
while ([rootVC isKindOfClass:[UINavigationController class]]) {
|
|
rootVC = [(UINavigationController *)rootVC topViewController];
|
|
}
|
|
return rootVC;
|
|
}
|
|
|
|
|
|
//获取当前屏幕显示的viewcontroller
|
|
+ (UIViewController *)getCurrentVC
|
|
{
|
|
UIViewController *rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
|
|
|
|
UIViewController *currentVC = [self getCurrentVCFrom:rootViewController];
|
|
|
|
return currentVC;
|
|
}
|
|
|
|
+ (UIViewController *)getCurrentVCFrom:(UIViewController *)rootVC
|
|
{
|
|
UIViewController *currentVC;
|
|
|
|
if ([rootVC presentedViewController]) {
|
|
// 视图是被presented出来的
|
|
|
|
rootVC = [rootVC presentedViewController];
|
|
}
|
|
|
|
if ([rootVC isKindOfClass:[UITabBarController class]]) {
|
|
// 根视图为UITabBarController
|
|
|
|
currentVC = [self getCurrentVCFrom:[(UITabBarController *)rootVC selectedViewController]];
|
|
|
|
} else if ([rootVC isKindOfClass:[UINavigationController class]]){
|
|
// 根视图为UINavigationController
|
|
|
|
currentVC = [self getCurrentVCFrom:[(UINavigationController *)rootVC visibleViewController]];
|
|
|
|
} else {
|
|
// 根视图为非导航类
|
|
|
|
currentVC = rootVC;
|
|
}
|
|
|
|
return currentVC;
|
|
}
|
|
|
|
|
|
//弹簧效果.
|
|
+(void)animationAlert:(UIView *)view{
|
|
|
|
CAKeyframeAnimation *popAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
|
|
|
|
popAnimation.duration = 0.4;
|
|
|
|
popAnimation.values = @[[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.01f, 0.01f, 1.0f)],
|
|
|
|
[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.1f, 1.1f, 1.0f)],
|
|
|
|
[NSValue valueWithCATransform3D:CATransform3DIdentity]];
|
|
|
|
popAnimation.keyTimes = @[@0.0f, @0.5f, @0.75f, @1.0f];
|
|
|
|
popAnimation.timingFunctions = @[[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
|
|
|
|
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
|
|
|
|
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
|
|
|
|
[view.layer addAnimation:popAnimation forKey:nil];
|
|
}
|
|
|
|
+ (NSString*)getOvertime:(NSString*)mStr{
|
|
NSTimeInterval interval =[mStr doubleValue] / 1000.0;
|
|
NSDate *date = [NSDate dateWithTimeIntervalSince1970:interval];
|
|
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
|
|
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
|
|
NSString *dateString = [formatter stringFromDate: date];
|
|
// NSLog(@"服务器返回的时间戳对应的时间是:%@",dateString);
|
|
return dateString;
|
|
}
|
|
|
|
//UIRectCornerTopLeft | UIRectCornerTopRight 指定圆角.
|
|
+(CAShapeLayer*)setShapeLayer:(CGRect)rect andWithRectCorner:(UIRectCorner)corners andWithNumCorner:(CGFloat)Cornerfloat{
|
|
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:corners cornerRadii:CGSizeMake(Cornerfloat, Cornerfloat)];
|
|
CAShapeLayer *maskLayer = [[CAShapeLayer alloc]init];
|
|
//设置大小
|
|
maskLayer.frame = rect;
|
|
//设置图形样子
|
|
maskLayer.path = maskPath.CGPath;
|
|
return maskLayer;
|
|
}
|
|
|
|
@end
|