DejalActivityView是国外的第三方库,可自定义文本内容和文本长度的菊花转加载指示器效果。该第三方库与其它hud存在不同,能够遮盖键盘;可以自定义遮盖NavigationBar或不遮盖NavigationBar,能够在status bar显示activity view等效果。该库github地址:https://github.com/Dejal/DejalActivityView

  DejalActivityView在iOS 8 之前的系统上存在bug,今天使用github上的最新版本存在同样的bug。我现在在给深圳一家智能家居公司zyyzn开发iPad版本的app,app中的加载提示使用了该第三方库。开发的app 是横版显示的,这时问题就出现了,DejalActivityView在iOS 7.1 系统上,当app为横版时,DejalActivityView提示框不能跟随app界面一致显示为横屏,如下图:

[DejalBezelActivityView activityViewForView:[UIApplication sharedApplication].keyWindow withLabel:@"正在登录,请稍后..."];

  上图中的提示效果与我期望的效果不一致,这时怎么办?是使用另外一套第三方库来替代它,比如MBProgressHUD,还是耐心去修改?因为我的iPad版app是在iPhone 版基础上修改的,iPhone版是竖版,iPad要做成横版,要是替换一套第三方提示库,工作量太大。还是耐心修改DejalActivityView吧。

  在DejalActivityView.m中,@implementation DejalBezelActivityView 的实现中找到 - (void)layoutSubviews,在该方法的末尾添加

 [self addObserver];
[self onDeviceOrientationChange:nil];

具体如下:

- (void)layoutSubviews;
{
// If we're animating a transform, don't lay out now, as can't use the frame property when transforming:
if (!CGAffineTransformIsIdentity(self.borderView.transform))
return; self.frame = [self enclosingFrame]; ......
...... 这些代码就不贴出来了,占位置
...... // Calculate the position of the label: horizontally centered and near the bottom of the border view:
CGRect labelFrame = self.activityLabel.frame;
labelFrame.origin.x = floor(0.5 * (borderFrame.size.width - labelFrame.size.width));
labelFrame.origin.y = borderFrame.size.height - labelFrame.size.height - 10.0;
self.activityLabel.frame = labelFrame; [self addObserver];
[self onDeviceOrientationChange:nil];
}

  addObserver方法的实现:

#pragma mark --
#pragma mark -- (1) - 解决该第三方库在iOS 8 之前的系统上,APP 横屏时不能跟随界面横着显示的bug,written by sunminmin 1/30/2015
// 接受状态栏变化通知中心监听状态栏的变化
- (void)addObserver
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onDeviceOrientationChange:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
}

  onDeviceOrientationChange方法实现:

// 根据监测得到的设备的方向旋转View
- (void)onDeviceOrientationChange:(id)sender
{
if ([[UIDevice currentDevice] systemVersion].floatValue < 8.0) {
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationLandscapeLeft) {
self.activityIndicator.superview.transform = CGAffineTransformMakeRotation(- M_PI_2);
}
if (orientation == UIInterfaceOrientationLandscapeRight) {
self.activityIndicator.superview.transform = CGAffineTransformMakeRotation(M_PI_2);
}
}
}

  @implementation DejalBezelActivityView 的 layoutSubviews方法中注册了监听者,那就需要在 dealloc方法中移除监听:

// 在dealloc中移除监听
- (void)dealloc
{
[self removeObserver];
} // 移除状态栏变化通知中心的监听
- (void)removeObserver
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
}

  做好上面的修改之后,DejalActivityView在iOS 7的设备上显示提示就正常了,但是还不够完美,为什么?因为在弹出DejalActivityView时,DejalActivityView会先旋转90度才正确显示为横版,这影响了效果,还不是我需要的效果。通过DejalActivityView的显示过程,我判断问题出现在它的动画效果上,那我就去找它的动画实现方法,哦,找到了,就是 - (void)animateShow;此时我需要在该方法中修改,问题出在iOS 8之前的系统上,首先就需要做系统版本判断,其次就是修改动画效果咯。

- (void)animateShow;
{
self.alpha = 0.0;
self.borderView.transform = CGAffineTransformMakeScale(3.0, 3.0); [UIView beginAnimations:nil context:nil];
// [UIView setAnimationDuration:5.0]; // Uncomment to see the animation in slow motion self.borderView.transform = CGAffineTransformIdentity;
self.alpha = 1.0; [UIView commitAnimations];
}

  在上面的 animateShow方法中,添加如下代码,具体实现为:

- (void)animateShow;
{
if ([[UIDevice currentDevice] systemVersion].floatValue >= 8.0) {
self.alpha = 0.0;
self.borderView.transform = CGAffineTransformMakeScale(3.0, 3.0); [UIView beginAnimations:nil context:nil];
// [UIView setAnimationDuration:5.0]; // Uncomment to see the animation in slow motion self.borderView.transform = CGAffineTransformIdentity;
self.alpha = 1.0; [UIView commitAnimations];
} else {
#pragma mark --
#pragma mark -- (2) - 解决该第三方库在iOS 8 之前的系统上,APP 横屏时不能跟随界面横着显示的bug,written by sunminmin 1/30/2015
self.alpha = 0.0;
[UIView beginAnimations:nil context:nil];
self.alpha = 1.0;
[UIView commitAnimations];
}
}

  使用动画让DejalActivityView消失的时候,注意iOS8之前的设备要注释到- (void)animateRemove 方法中的 self.borderView.transform = CGAffineTransformMakeScale(0.5, 0.5);

- (void)animateRemove;
{
if (self.showNetworkActivityIndicator)
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO; self.borderView.transform = CGAffineTransformIdentity; [UIView beginAnimations:nil context:nil];
// [UIView setAnimationDuration:5.0]; // Uncomment to see the animation in slow motion
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(removeAnimationDidStop:finished:context:)];
if ([[UIDevice currentDevice] systemVersion].floatValue >= 8.0) {
self.borderView.transform = CGAffineTransformMakeScale(0.5, 0.5);
} else {
#pragma mark --
#pragma mark -- (3) - 解决该第三方库在iOS 8 之前的系统上,APP 横屏时不能跟随界面横着显示的bug,written by sunminmin 1/30/2015
// self.borderView.transform = CGAffineTransformMakeScale(0.5, 0.5);
}
self.alpha = 0.0; [UIView commitAnimations];
}

  到现在为止,那就修改好了,在iOS 7的设备上再次执行下面的代码,预期的效果出来了,如下图:

[DejalBezelActivityView activityViewForView:[UIApplication sharedApplication].keyWindow withLabel:@"正在登录,请稍后..."];

修改后的DejalActivityView库的下载地址为:http://pan.baidu.com/s/1i3y2wgl 百度网盘

最新文章

  1. vmware 中ubuntu客户机 安装vmware tool vmhgfs 共享文件夹失败处理
  2. osg 示例程序解析之osgdelaunay
  3. XSLT简介
  4. 【CodeVS 3160】最长公共子串
  5. Spark排错与优化
  6. Android UI开发第四十一篇——墨迹天气3.0引导界面及动画实现
  7. XPath常用定位节点元素语句总结
  8. extern关键字的使用
  9. &lt;八&gt;面向对象分析之UML核心元素之分析类
  10. Castle ActiveRecord学习实践
  11. JQuery里的原型prototype分析
  12. 发现一个好的开源项目:lomoX(挑着看,每天看一点,看一年就ok了)——用Webkit开发桌面软件,炫
  13. 【Linux】鸟哥的Linux私房菜基础学习篇整理(五)
  14. vs code(egret wing) php配置与调试
  15. Groovy常见语法汇总
  16. 不同浏览器创建 ajax XMLHTTPRequest对象的方法及兼容性问题总结
  17. Python Django系统
  18. 关于web前端中遇到的html,css小知识点
  19. Beta冲刺(5/5)(麻瓜制造者)
  20. uva-10098

热门文章

  1. 单细胞ENS发育数据库
  2. ggplot常见语法汇总查询
  3. typescript - 7.模块
  4. Python3基础 函数 函数名赋值操作
  5. navicat for mysql 如何设置字段唯一
  6. Visual Studio 2017 vcvarsall.bat 环境配置对应关系
  7. xshell的ssh连接频繁提示Socket error Event: 32 Error: 10053(待验证)
  8. [LeetCode] 750. Number Of Corner Rectangles 边角矩形的数量
  9. Spring boot后台搭建二集成Shiro权限控制
  10. kali 扫描之burp Suite学习笔记1