diff --git a/Examples/Objective-C/NYSExampleObjC.xcodeproj/project.pbxproj b/Examples/Objective-C/NYSExampleObjC.xcodeproj/project.pbxproj index 269cfde..56dde2e 100644 --- a/Examples/Objective-C/NYSExampleObjC.xcodeproj/project.pbxproj +++ b/Examples/Objective-C/NYSExampleObjC.xcodeproj/project.pbxproj @@ -29,6 +29,7 @@ C891E85E24B8562C00AF0019 /* UMManager.m in Sources */ = {isa = PBXBuildFile; fileRef = C891E85D24B8562C00AF0019 /* UMManager.m */; }; C891E86324B856DF00AF0019 /* UserManager.m in Sources */ = {isa = PBXBuildFile; fileRef = C891E86224B856DF00AF0019 /* UserManager.m */; }; C891E86824B85C0900AF0019 /* NYSNewfeatureViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C891E86724B85C0900AF0019 /* NYSNewfeatureViewController.m */; }; + C89E827E2B733B28002BEC52 /* NYSNoticeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C89E827D2B733B28002BEC52 /* NYSNoticeViewController.m */; }; C8C431A724BC351E0041311C /* themejson_night.json in Resources */ = {isa = PBXBuildFile; fileRef = C8C431A424BC351E0041311C /* themejson_night.json */; }; C8C431A824BC351E0041311C /* themejson_day.json in Resources */ = {isa = PBXBuildFile; fileRef = C8C431A624BC351E0041311C /* themejson_day.json */; }; C8C58D2B24B94A1200CFB68F /* NYSOpenViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C8C58D2924B94A1200CFB68F /* NYSOpenViewController.m */; }; @@ -88,6 +89,8 @@ C891E86224B856DF00AF0019 /* UserManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = UserManager.m; sourceTree = ""; }; C891E86624B85C0900AF0019 /* NYSNewfeatureViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NYSNewfeatureViewController.h; sourceTree = ""; }; C891E86724B85C0900AF0019 /* NYSNewfeatureViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NYSNewfeatureViewController.m; sourceTree = ""; }; + C89E827C2B733B28002BEC52 /* NYSNoticeViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NYSNoticeViewController.h; sourceTree = ""; }; + C89E827D2B733B28002BEC52 /* NYSNoticeViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NYSNoticeViewController.m; sourceTree = ""; }; C8C431A424BC351E0041311C /* themejson_night.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = themejson_night.json; sourceTree = ""; }; C8C431A624BC351E0041311C /* themejson_day.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = themejson_day.json; sourceTree = ""; }; C8C58D2824B94A1200CFB68F /* NYSOpenViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NYSOpenViewController.h; sourceTree = ""; }; @@ -346,6 +349,8 @@ children = ( C82DD0F52B6F48ED00FD2BD8 /* NYSHomeViewController.h */, C82DD0F62B6F48ED00FD2BD8 /* NYSHomeViewController.m */, + C89E827C2B733B28002BEC52 /* NYSNoticeViewController.h */, + C89E827D2B733B28002BEC52 /* NYSNoticeViewController.m */, ); path = Controller; sourceTree = ""; @@ -532,6 +537,7 @@ C891E85E24B8562C00AF0019 /* UMManager.m in Sources */, C891E80624B8112200AF0019 /* NYSLoginViewController.m in Sources */, C8C58D4A24B9647500CFB68F /* NYSNewViewController.m in Sources */, + C89E827E2B733B28002BEC52 /* NYSNoticeViewController.m in Sources */, C8C58D5924B9B16B00CFB68F /* NYSUserInfo.m in Sources */, C891E80224B8110400AF0019 /* NYSTabBarViewController.m in Sources */, C8C58D5A24B9B16B00CFB68F /* NYSProfile.m in Sources */, diff --git a/Examples/Objective-C/NYSExampleObjC.xcworkspace/xcuserdata/nigang.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/Examples/Objective-C/NYSExampleObjC.xcworkspace/xcuserdata/nigang.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100644 index 0000000..54b6a7c --- /dev/null +++ b/Examples/Objective-C/NYSExampleObjC.xcworkspace/xcuserdata/nigang.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,20 @@ + + + + + + + + + diff --git a/Examples/Objective-C/NYSExampleObjC/Modules/Home/Controller/NYSHomeViewController.m b/Examples/Objective-C/NYSExampleObjC/Modules/Home/Controller/NYSHomeViewController.m index 59aab96..39d3d99 100644 --- a/Examples/Objective-C/NYSExampleObjC/Modules/Home/Controller/NYSHomeViewController.m +++ b/Examples/Objective-C/NYSExampleObjC/Modules/Home/Controller/NYSHomeViewController.m @@ -7,6 +7,7 @@ // #import "NYSHomeViewController.h" +#import "NYSNoticeViewController.h" @interface NYSHomeViewController () @@ -24,16 +25,11 @@ - (void)viewDidLoad { [self.view addSubview:self.tableView]; - [self initNavItem]; + self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"notification_icon"] imageWithRenderingMode:UIImageRenderingModeAutomatic] style:UIBarButtonItemStyleDone target:self action:@selector(rightItemOnclicked)]; } -- (void)initNavItem { - UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"notification_icon"] imageWithRenderingMode:UIImageRenderingModeAutomatic] style:UIBarButtonItemStyleDone target:self action:nil]; - WS(weakSelf); - [rightItem setActionBlock:^(id _Nonnull sender) { - [weakSelf.navigationController pushViewController:NYSBaseViewController.new animated:YES]; - }]; - self.navigationItem.rightBarButtonItem = rightItem; +- (void)rightItemOnclicked { + [self.navigationController pushViewController:NYSNoticeViewController.new animated:YES]; } - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView { diff --git a/Examples/Objective-C/NYSExampleObjC/Modules/Home/Controller/NYSNoticeViewController.h b/Examples/Objective-C/NYSExampleObjC/Modules/Home/Controller/NYSNoticeViewController.h new file mode 100644 index 0000000..4906ac7 --- /dev/null +++ b/Examples/Objective-C/NYSExampleObjC/Modules/Home/Controller/NYSNoticeViewController.h @@ -0,0 +1,17 @@ +// +// NYSNoticeViewController.h +// NYSExampleObjC +// +// Created by niyongsheng on 2024/2/7. +// Copyright © 2024 niyongsheng. All rights reserved. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface NYSNoticeViewController : NYSBaseViewController + +@end + +NS_ASSUME_NONNULL_END diff --git a/Examples/Objective-C/NYSExampleObjC/Modules/Home/Controller/NYSNoticeViewController.m b/Examples/Objective-C/NYSExampleObjC/Modules/Home/Controller/NYSNoticeViewController.m new file mode 100644 index 0000000..4ab8356 --- /dev/null +++ b/Examples/Objective-C/NYSExampleObjC/Modules/Home/Controller/NYSNoticeViewController.m @@ -0,0 +1,24 @@ +// +// NYSNoticeViewController.m +// NYSExampleObjC +// +// Created by niyongsheng on 2024/2/7. +// Copyright © 2024 niyongsheng. All rights reserved. +// + +#import "NYSNoticeViewController.h" + +@interface NYSNoticeViewController () + +@end + +@implementation NYSNoticeViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + + [self.view addSubview:self.collectionView]; + [UIView showLoadingWithTintColor:nil]; +} + +@end diff --git a/NYSUIKit/Category/UITextField+NYS.h b/NYSUIKit/Category/UITextField+NYS.h index 290ca70..98d9e6d 100644 --- a/NYSUIKit/Category/UITextField+NYS.h +++ b/NYSUIKit/Category/UITextField+NYS.h @@ -7,10 +7,11 @@ #import +IB_DESIGNABLE @interface UITextField (NYS) /// 最大可输入位数 -@property (assign, nonatomic) NSInteger maxLength; +@property (assign, nonatomic) IBInspectable NSInteger maxLength; @end diff --git a/NYSUIKit/Category/UIView+NYS.h b/NYSUIKit/Category/UIView+NYS.h index 6115e28..e422085 100644 --- a/NYSUIKit/Category/UIView+NYS.h +++ b/NYSUIKit/Category/UIView+NYS.h @@ -21,10 +21,13 @@ IB_DESIGNABLE /// 圆角半径 @property (nonatomic, assign) IBInspectable CGFloat cornerRadius; -/// 添加加载动画 -+ (UIView*)loadingAnimation; -/// 移除加载动画 -+ (void)removeLoadingAnimation; +/// 显示加载动画(毛玻璃效果) +/// - Parameter tintColor: 指示器颜色 ++ (UIView*)showLoadingWithTintColor:(UIColor *)tintColor; + +/// 显示加载动画 +/// - Parameter image: 自定义旋转图 ++ (UIView*)showLoadingWithImage:(UIImage *)image; @property (nonatomic, copy) NYSTapActionBlock tapActionBlock; /// 添加点击事件 diff --git a/NYSUIKit/Category/UIView+NYS.m b/NYSUIKit/Category/UIView+NYS.m index db93e2a..041096b 100644 --- a/NYSUIKit/Category/UIView+NYS.m +++ b/NYSUIKit/Category/UIView+NYS.m @@ -6,9 +6,12 @@ // #import "UIView+NYS.h" +#import "UIImage+NYS.h" +#import "NYSUIKitUtilities.h" +#import + #define kLinePix ( 1 / [UIScreen mainScreen].scale) -#import static const char *NYSTapActionKey = "NYSTapActionKey"; @implementation UIView (NYS) @@ -39,7 +42,7 @@ - (CGFloat)cornerRadius { } #pragma mark - Loading Animation -+ (UIView*)loadingAnimation { ++ (UIView*)showLoadingWithImage:(UIImage *)image { UIWindow *keywindow = nil; for (UIWindow *window in [UIApplication sharedApplication].windows) { if (window.isKeyWindow) { @@ -47,22 +50,37 @@ + (UIView*)loadingAnimation { break; } } + CGFloat width = keywindow.frame.size.width; CGFloat height = keywindow.frame.size.height; - UIView *animationBg = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, height)]; - animationBg.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.2]; - UIImageView *animation = [[UIImageView alloc] init]; - animation.frame = CGRectMake(0, 0, 80, 80); - animation.center = animationBg.center; - [animationBg addSubview:animation]; -// NSURL *gifImageUrl = [[NSBundle mainBundle] URLForResource:@"loading_gif_plane" withExtension:@"gif"]; -// [animation setImageURL:gifImageUrl]; - animationBg.tag = 1000001; - [keywindow addSubview:animationBg]; - return animationBg; + UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, height)]; + bgView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.45]; + [bgView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(removeLoadingAnimation:)]]; + bgView.userInteractionEnabled = YES; + bgView.alpha = 0; + + UIImageView *animation = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; + animation.center = CGPointMake(width / 2.0, height / 2.0); + animation.contentMode = UIViewContentModeCenter; + [animation setImage:image ? image : [[NYSUIKitUtilities imageNamed:@"waiting_icon"] imageByResizeToSize:CGSizeMake(40, 40)]]; + [bgView addSubview:animation]; + + CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"]; + rotationAnimation.fromValue = [NSNumber numberWithFloat:0]; + rotationAnimation.toValue = [NSNumber numberWithFloat:M_PI * 2.0]; + rotationAnimation.duration = 1.25; // 旋转一周所需时间 + rotationAnimation.repeatCount = HUGE_VALF; // 无限循环 + [animation.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"]; + + [keywindow addSubview:bgView]; + [UIView transitionWithView:bgView duration:0.75 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{ + bgView.alpha = 1.0; + } completion:nil]; + + return bgView; } -+ (void)removeLoadingAnimation { ++ (UIView*)showLoadingWithTintColor:(UIColor *)tintColor { UIWindow *keywindow = nil; for (UIWindow *window in [UIApplication sharedApplication].windows) { if (window.isKeyWindow) { @@ -70,8 +88,45 @@ + (void)removeLoadingAnimation { break; } } - UIView *animationBg = [keywindow viewWithTag:1000001]; - [animationBg removeFromSuperview]; + + CGFloat width = keywindow.frame.size.width; + CGFloat height = keywindow.frame.size.height; + UIBlurEffectStyle blurEffectStyle = UIBlurEffectStyleLight; + UIColor *color = UIColor.grayColor; + if (@available(iOS 13.0, *)) { + if (UITraitCollection.currentTraitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) { + blurEffectStyle = UIBlurEffectStyleDark; + color = UIColor.whiteColor; + } else { + blurEffectStyle = UIBlurEffectStyleLight; + } + } + UIVisualEffectView *bgView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:blurEffectStyle]]; + bgView.frame = CGRectMake(0, 0, width, height); + [bgView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(removeLoadingAnimation:)]]; + bgView.userInteractionEnabled = YES; + bgView.alpha = 0; + + UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleLarge]; + activityIndicator.color = tintColor ? tintColor : color; + activityIndicator.center = CGPointMake(width / 2.0, height / 2.0); + [activityIndicator startAnimating]; + [bgView.contentView addSubview:activityIndicator]; + + [keywindow addSubview:bgView]; + [UIView transitionWithView:bgView duration:0.75 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{ + bgView.alpha = 1.0; + } completion:nil]; + + return bgView; +} + ++ (void)removeLoadingAnimation:(UITapGestureRecognizer *)gesture { + [UIView animateWithDuration:0.75 animations:^{ + gesture.view.alpha = 0.0; + } completion:^(BOOL finished) { + [gesture.view removeFromSuperview]; + }]; } #pragma mark - Tap Action diff --git a/README.md b/README.md index 762ef2f..aeb26dd 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,9 @@ NYSUIKit │ ├─ NYSUIKit.bundle │ │ ├─ Info.plist │ │ ├─ en.lproj +│ │ ├─ es.lproj +│ │ ├─ ja.lproj +│ │ ├─ ko.lproj │ │ ├─ lao.lproj │ │ ├─ zh-Hans.lproj │ │ └─ zh-Hant.lproj