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. powshell 输出字符编码的问题,设置为utf-8

    https://blog.csdn.net/qianxiao_1/article/details/79463409 $PSDefaultParameterValues['Out-File:Encodi ...

  2. sklearn逻辑回归(Logistic Regression,LR)调参指南

    python信用评分卡建模(附代码,博主录制) https://study.163.com/course/introduction.htm?courseId=1005214003&utm_ca ...

  3. CEF 访问需要认证网页或接口(在Request的Headers中添加认证Token)

    转载:https://blog.csdn.net/wdw984/article/details/85275289 1.首先要让我们自己的CefClient这个类公有继承CefRequestHandle ...

  4. 运维笔记--postgresql占用CPU问题定位

    运维笔记--postgresql占用CPU问题定位 场景描述: 业务系统访问变慢,登陆服务器查看系统负载并不高,然后查看占用CPU较高的进程,发现是连接数据库的几个进程占用系统资源较多. 处理方式: ...

  5. zk单点部署

    一.环境准备 当前环境:centos7.3一台软件版本:zookeeper-3.5.2部署目录:/usr/local/zookeeper启动端口:2181配置文件:/usr/local/zookeep ...

  6. postgrelsql 的 wm_concat : string_agg

    string_agg,array_agg 这两个函数的功能大同小异,只不过合并数据的类型不同 array_agg(expression) 把表达式变成一个数组 一般配合 array_to_string ...

  7. [转自baidu]修正古人五行,《七行说》之提出

    一.论原五行相生.相克关系不妥之处: 祖国医学原“五行说”即金.木.水.火.土.在五行学说中说相生规律为:金生水:水生木:木生火:火生土:土生金.相克规律为:火克金:金克木:木克土:土克水:水克火.这 ...

  8. [LeetCode] 87. Scramble String 爬行字符串

    Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrin ...

  9. [LeetCode] 268. Missing Number 缺失的数字

    Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...

  10. oracle 添加字段

    alter table 表名 add 新增字段名(类型+长度); #添加字段 alter table asset_orders add remark varchar2(255); #查看 descri ...