iOS开源项目学习——SVProgressHUD
来源:互联网 发布:什么是云计算 视频 编辑:程序博客网 时间:2024/04/30 02:24
SVProgressHUD
代码片段
在SVProgressHUD.h
中有如下代码:
#if __IPHONE_OS_VERSION_MAX_ALLOWED < 70000#define UI_APPEARANCE_SELECTOR#endif
__IPHONE_OS_VERSION_MAX_ALLOWED
用法与意义请参考
- iOS开发之多系统版本兼容
- What are the common use cases for __IPHONE_OS_VERSION_MAX_ALLOWED?
UI_APPEARANCE_SELECTOR
请参考
- UIKit: UIApearance
- 使用UIAppearance协议自定义视图
在申明方法是见到如下的用法:
+ (void)showWithMaskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use show and setDefaultMaskType: instead.")));
__attribute__
可以设置函数属性(Function Attribute )、变量属性(Variable Attribute )和类型属性(Type Attribute ),详细的请见:
- iOS宏和attribute
- 神奇的attribute
iOS UIWindow的理解
如下代码:
NSEnumerator *frontToBackWindows = [UIApplication.sharedApplication.windows reverseObjectEnumerator]; for (UIWindow *window in frontToBackWindows) { BOOL windowOnMainScreen = window.screen == UIScreen.mainScreen; BOOL windowIsVisible = !window.hidden && window.alpha > 0; BOOL windowLevelNormal = window.windowLevel == UIWindowLevelNormal; if(windowOnMainScreen && windowIsVisible && windowLevelNormal) { [window addSubview:self.overlayView]; break; } }
UIWindow
在显示的时候会根据UIWindowLevel进行排序的,即Level高的将排在所有Level比他低的层级的前面。下面我们来看UIWindowLevel
的定义:
const UIWindowLevel UIWindowLevelNormal;const UIWindowLevel UIWindowLevelAlert;const UIWindowLevel UIWindowLevelStatusBar;typedef CGFloat UIWindowLevel;
它们级别的高低顺序从小到大为Normal < StatusBar < Alert
关于UIWindow
的内容请参考:
- UIWindow in iOS
willMoveToSuperview
在SVIndefiniteAnimatedView.m
中如下:
- (void)willMoveToSuperview:(UIView*)newSuperview { if (newSuperview) { [self layoutAnimatedLayer]; } else { [_indefiniteAnimatedLayer removeFromSuperlayer]; _indefiniteAnimatedLayer = nil; }}
willMoveToSuperview的作用如下:
When a view is added to a superview, the system sends willMoveToSuperview: to the view. The parameter is the new superview.
When a view is removed from a superview, the system sends willMoveToSuperview: to the view. The parameter is nil.
You can’t prevent the system from sending willMoveToSuperview: when you remove the view from its superview, but you can check the parameter:
- (void)willMoveToSuperview:(UIView *)newSuperview {if (newSuperview != nil) { // not a removeFromSuperview situation }}
从bundle中加载图片
SVProgressHUD使用到的图片,位于SVProgressHUD.bundle
中,其加载图片的方式如下:
//资源 NSBundle *bundle = [NSBundle bundleForClass:[SVProgressHUD class]]; NSURL *url = [bundle URLForResource:@"SVProgressHUD" withExtension:@"bundle"]; NSBundle *imageBundle = [NSBundle bundleWithURL:url]; //图片 UIImage* infoImage = [UIImage imageWithContentsOfFile:[imageBundle pathForResource:@"info" ofType:@"png"]]; UIImage* successImage = [UIImage imageWithContentsOfFile:[imageBundle pathForResource:@"success" ofType:@"png"]]; UIImage* errorImage = [UIImage imageWithContentsOfFile:[imageBundle pathForResource:@"error" ofType:@"png"]];
动画
fadeIn
渐入动画,开始出现时,alpha和HUD的transform为:
// Zoom HUD a little to make a nice appear / pop up animation self.hudView.transform = CGAffineTransformScale(self.hudView.transform, 1.3, 1.3); // Set initial values to handle iOS 7 (and above) UIToolbar which not answers well to hierarchy opacity change self.alpha = 0.0f; self.hudView.alpha = 0.0f;
动画结束的状态为:
__block void (^animationsBlock)(void) = ^{ __strong SVProgressHUD *strongSelf = weakSelf; if(strongSelf) { // Shrink HUD to finish pop up animation strongSelf.hudView.transform = CGAffineTransformScale(strongSelf.hudView.transform, 1/1.3f, 1/1.3f); strongSelf.alpha = 1.0f; strongSelf.hudView.alpha = 1.0f; } };
相当于有一个弹性的动作。
动画完成后还有执行一段动作,定义为一个completionBlock:
__block void (^completionBlock)(void) = ^{ __strong SVProgressHUD *strongSelf = weakSelf; if(strongSelf) { /// Register observer <=> we now have to handle orientation changes etc. [strongSelf registerNotifications]; // Post notification to inform user [[NSNotificationCenter defaultCenter] postNotificationName:SVProgressHUDDidAppearNotification object:strongSelf userInfo:[strongSelf notificationUserInfo]]; } // Update accesibilty UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, nil); UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, status); };
动画执行的过程为:
//渐入动画,变化alpha和transfrom if (self.fadeInAnimationDuration > 0) { // Animate appearance [UIView animateWithDuration:self.fadeInAnimationDuration delay:0 options:(UIViewAnimationOptions) (UIViewAnimationOptionAllowUserInteraction | UIViewAnimationCurveEaseOut | UIViewAnimationOptionBeginFromCurrentState) animations:^{ animationsBlock(); } completion:^(BOOL finished) { completionBlock(); }]; } else { animationsBlock(); completionBlock(); }
fadeOut
fadeOut动画与fadeIn动画类似。
HUD实现
#
- iOS开源项目学习——SVProgressHUD
- iOS——加载进度示的SVProgressHUD 用法
- [IOS]SVProgressHUD
- iOS----SVProgressHUD
- iOS开发——MBProgressHUD 与 SVProgressHUD iOS提示框的优缺点
- iOS基础——UI控件之UIAlertController、UINavigationController、Segue、SVProgressHUD
- iOS:SVProgressHUD控件使用
- iOS SVProgressHUD 简单使用
- iOS SVProgressHUD 用法
- 开源提示框SVProgressHUD使用备忘录
- iOS ----- MBProgressHUD、SVProgressHUD基本使用方法
- iOS 进度框(二) SVProgressHUD
- iOS开源项目学习——JSQMessagesViewController
- iOS开源项目学习—— AFNetworking
- svprogresshud
- SVProgressHUD
- SVProgressHUD
- SVProgressHUD
- IP地址或DNS没有获取正确
- 编写poc和exploit的几款常用工具介绍
- 设置checkBox复选框的大小
- Android面试题大集结
- QCon北京:业务监控与APM技术实践
- iOS开源项目学习——SVProgressHUD
- (OK) Android —— gem5跑bench (Android) 过程记录
- linux系统访问win2003 FTP连接时出现“227 Entering Passive Mode”的解决方法
- $.ajax()里面data参数的含义、用法
- PHP startup: Unable to load dynamic library错误的错误
- Android在代码中修改EditText光标
- 读《程序员的自我修养 —— 库与运行库》乱摘
- iOS 获取当前时间
- NSThread的简单使用