修正DejalActivityView在iOS8之前系统上存在的Bug
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的更多相关文章
- sqlite在Android上的一个bug:SQLiteCantOpenDatabaseException when nativeExecuteForCursorWindow
更多内容在这里查看 https://ahangchen.gitbooks.io/windy-afternoon/content/ ::-/com.company.product W/System.er ...
- 在配有英特尔® Iris™ 显卡的系统上通过优化对 Just Cause 3 进行增强
高端 PC 继续通过高性能显卡驱动桌面游戏. 一流的"梦想机器"基于第六代智能 英特尔® 酷睿™ 处理器i7-6700K等 CPU,通常与高端独立显卡配合使用以运行要求最严苛的游戏 ...
- 基于英特尔® 至强™ 处理器 E5 产品家族的多节点分布式内存系统上的 Caffe* 培训
原文链接 深度神经网络 (DNN) 培训属于计算密集型项目,需要在现代计算平台上花费数日或数周的时间方可完成. 在最近的一篇文章<基于英特尔® 至强™ E5 产品家族的单节点 Caffe 评分和 ...
- win10调用局域网内xp系统上的打印机
首先在xp系统上配置允许远程连接,然后设置账户密码,最后配置打印机,允许共享. 打开自己win10 ,win+R ,输入\\目标电脑ip\打印机名,确定,输入账户,密码. win+X - P-进入控制 ...
- 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 ...
- 数据终端设备与无线通信模块之间串行通信链路复用协议(TS27.010)在嵌入式系统上的开发【转】
转自:http://blog.csdn.net/hellolwl/article/details/6164449 目录(?)[-] 协议介绍 模块协议介绍 1 命令包格式 2 ...
- 在Mac系统上配置Android真机调试环境
在Mac系统上配置Android真机调试环境 mac上配置安卓环境还说挺方便的,真机调试也比win上要好一些.win上被各种软件强行安装了xxx助手. 在mac上就了一个干净的感觉. 下载Androi ...
- IBM X3850 Windows 无法安装到这个磁盘。选中的磁盘具有MBR分区表。在 EFI 系统上,Windows 只能安装到 GPT 磁盘
以前安装的是window2003 32位, 改装为2012 64位的时候.出现 Windows 无法安装到这个磁盘.选中的磁盘具有MBR分区表.在 EFI 系统上,Windows 只能安装到 GPT ...
- 解决Inno Setup制作中文安装包在非中文系统上显示乱码的问题
尼玛,好几个月没更新了.囧... 目前我司新的客户端开发已经接近尾声,该改的bug已经改完,该重构的地方也都差不多了.视觉效果也已经根据美工的样式改完了.所以,就差制作安装包了.正所谓万事俱备,只欠东 ...
随机推荐
- 升级ruby的版本 https://gems.ruby-china.com/
升级ruby版本,有时候安装ruby的版本过低,需要进行升级,例如安装在centos6.7安装fpm需要ruby版本在1.9以上. 1.主机环境如下: 1 [root@test ~]# cat /et ...
- win 10 关闭或打开 测试模式
一.关闭测试模式 方法: 以管理员身份运行 cmd 运行:bcdedit /set testsigning off 重启电脑 二.开启测试模式 以管理员身份运行 cmd 运行:bcdedit /set ...
- db2常用操作命令
1. 打开命令行窗口 #db2cmd 2. 打开控制中心 # db2cmd db2cc 3. 打开命令编辑器 db2cmd db2ce =====操作数据库命令===== 4. 启动数据库实例 #db ...
- RSA 签名、验证、加密、解密帮助类
import java.io.IOException; import java.security.InvalidKeyException; import java.security.KeyFactor ...
- Grafana修改背景色
grafana默认主题色是黑底白字,我们将它修改成白底黑字: in /etc/grafana/grafana.ini uncomment line and set default_theme = li ...
- [LeetCode] 712. Minimum ASCII Delete Sum for Two Strings 两个字符串的最小ASCII删除和
Given two strings s1, s2, find the lowest ASCII sum of deleted characters to make two strings equal. ...
- python基础篇(六)
PYTHON基础篇(六) 正则模块re A:正则表达式和re模块案例 B:re模块的内置方法 时间模块time A:时间模块的三种表示方式 B:时间模块的相互转换 随机数模块random A:随机数模 ...
- Clean code 关于注释、函数、命名的感想
最近在看代码整洁之道(Clean code)这本书,其实看的有点痛苦,因为越看就会越想自己写的代码是什么鬼?一些不知所云的命名,不整洁的代码格式,本想诠释代码的意思却添加了一段段废话,还有那些被强制加 ...
- QT_QML 界面设计Row和Column布局
Column与Row的使用方式类似,下面以Column为例子: Column{ x: label_poseParamValue.x + label_poseParamValue.width + 10 ...
- LeetCode 572. 另一个树的子树(Subtree of Another Tree) 40
572. 另一个树的子树 572. Subtree of Another Tree 题目描述 给定两个非空二叉树 s 和 t,检验 s 中是否包含和 t 具有相同结构和节点值的子树.s 的一个子树包括 ...