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 百度网盘

修正DejalActivityView在iOS8之前系统上存在的Bug的更多相关文章

  1. sqlite在Android上的一个bug:SQLiteCantOpenDatabaseException when nativeExecuteForCursorWindow

    更多内容在这里查看 https://ahangchen.gitbooks.io/windy-afternoon/content/ ::-/com.company.product W/System.er ...

  2. 在配有英特尔® Iris™ 显卡的系统上通过优化对 Just Cause 3 进行增强

    高端 PC 继续通过高性能显卡驱动桌面游戏. 一流的"梦想机器"基于第六代智能 英特尔® 酷睿™ 处理器i7-6700K等 CPU,通常与高端独立显卡配合使用以运行要求最严苛的游戏 ...

  3. 基于英特尔® 至强™ 处理器 E5 产品家族的多节点分布式内存系统上的 Caffe* 培训

    原文链接 深度神经网络 (DNN) 培训属于计算密集型项目,需要在现代计算平台上花费数日或数周的时间方可完成. 在最近的一篇文章<基于英特尔® 至强™ E5 产品家族的单节点 Caffe 评分和 ...

  4. win10调用局域网内xp系统上的打印机

    首先在xp系统上配置允许远程连接,然后设置账户密码,最后配置打印机,允许共享. 打开自己win10 ,win+R ,输入\\目标电脑ip\打印机名,确定,输入账户,密码. win+X - P-进入控制 ...

  5. 64位的Ubuntu系统上使用汇编nasm和C语言

    64位的Ubuntu系统上使用汇编nasm和C语言 $ nasm -f elf foo.asm -o foo.o$ gcc -c bar.c -o bar.o$ ld -s  foo.o bar.o ...

  6. 数据终端设备与无线通信模块之间串行通信链路复用协议(TS27.010)在嵌入式系统上的开发【转】

    转自:http://blog.csdn.net/hellolwl/article/details/6164449 目录(?)[-] 协议介绍 模块协议介绍 1            命令包格式 2   ...

  7. 在Mac系统上配置Android真机调试环境

    在Mac系统上配置Android真机调试环境 mac上配置安卓环境还说挺方便的,真机调试也比win上要好一些.win上被各种软件强行安装了xxx助手. 在mac上就了一个干净的感觉. 下载Androi ...

  8. IBM X3850 Windows 无法安装到这个磁盘。选中的磁盘具有MBR分区表。在 EFI 系统上,Windows 只能安装到 GPT 磁盘

    以前安装的是window2003 32位, 改装为2012 64位的时候.出现 Windows 无法安装到这个磁盘.选中的磁盘具有MBR分区表.在 EFI 系统上,Windows 只能安装到 GPT ...

  9. 解决Inno Setup制作中文安装包在非中文系统上显示乱码的问题

    尼玛,好几个月没更新了.囧... 目前我司新的客户端开发已经接近尾声,该改的bug已经改完,该重构的地方也都差不多了.视觉效果也已经根据美工的样式改完了.所以,就差制作安装包了.正所谓万事俱备,只欠东 ...

随机推荐

  1. [E2E_L9]GOMFCTemplate的融合进阶

    在前面出现的融合方法中,最突出的问题就是每次运算,都需要将整个推断的过程全部操作一遍,这样肯定是费时间的--所以我们需要将能够独立的地方独立出来,但是这个过中非常容易出现溢出的错误--经过一段时间的尝 ...

  2. jenkins报错Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password) 的处理

    问题背景:jenkins服务器发布代码后需要执行删除缓存的操作ssh -p222 eus_pe_devadmin@1.1.1.1 "sudo rm -rf /dev/shm/nginx/hi ...

  3. [译]如何取消本地的git commit提交?

    git reset HEAD~1 原文来源:https://stackoverflow.com/questions/4850717/how-to-cancel-a-local-git-commit

  4. 判断命令test

    判断命令test一般用于脚本当中,可以简写为中括号[ ].其会对跟随的条件进行判断,一般可以分为数值判断.字符串判断和文件判断.语法格式为test [判断条件]或[ 判断条件 ],注意中括号[ ]与判 ...

  5. Windows系统因“CredSSP加密Oracle修正”无法远程连接

    解决办法如下: 在电脑本机运行(快捷键 Win+R)输入:gpedit.msc 回车: 计算机配置->管理模板->系统->凭据分配->右侧找到“加密Oracle凭据”双击-&g ...

  6. consul删除无效实例

    consul删除无效实例删除无效服务删除无效节点删除无效服务http://127.0.0.1:8500/v1/agent/service/deregister/test-9c14fa595ddfb8f ...

  7. Centos7挂载新硬盘

    1.查看系统是否检测到新的硬盘设备 ls /dev/ |grep sd linux 中所有外设都会在这个目录下,对应一个文件,其中第一块硬盘是sda,第二块硬盘是sdb,第三块硬盘是sdc.其中sda ...

  8. LeetCode 84. 柱状图中最大的矩形(Largest Rectangle in Histogram)

    84. 柱状图中最大的矩形 84. Largest Rectangle in Histogram

  9. [转帖]IBM报告:多国央行考虑发行数字货币 最快5年内问世

    IBM报告:多国央行考虑发行数字货币 最快5年内问世 https://news.cnblogs.com/n/646001/ DCEP 中国央行可能是第一家发布 数字货币的央行 DCEP 是基于 UTX ...

  10. Linux学习-防火墙-Selinux-配置本地YUM源

    关闭防火墙并设置开机不启动 systemctl status firewalld.service #查看firewalld状态systemctl stop firewalld #关闭systemctl ...