判断两个控件在同一个Window上是否有重叠
判断两个控件在同一个Window上是否有重叠
//对UIView写分类
- (BOOL)intersectWithView:(UIView *)view; - (BOOL)intersectWithView:(UIView *)view
{
UIWindow *window = [UIApplication sharedApplication].keyWindow;
CGRect selfRect = [self convertRect:self.bounds toView:window];
CGRect viewRect = [view convertRect:view.bounds toView:window];
return CGRectIntersectsRect(selfRect, viewRect);
}
添加一个更高级别的UIWindow,目的点击状态栏时让ScrollView滚动到顶部
//.h文件
#import <Foundation/Foundation.h> @interface JGTopWindow : NSObject
+ (void)show;
@end //.m文件
#import "JGTopWindow.h" @implementation JGTopWindow static UIWindow *window_;
+ (void)show
{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
window_ = [[UIWindow alloc] init];
window_.frame = [UIApplication sharedApplication].statusBarFrame;
// 窗口默认显示黑色
window_.backgroundColor = [UIColor clearColor];
// UIWindowLevelAlert > UIWindowLevelStatusBar > UIWindowLevelNormal
// 窗口默认等级是UIWindowLevelNormal,等级最低,放在最下层,点击手势被拦截,无法被监听到
window_.windowLevel = UIWindowLevelAlert;
// 默认是隐藏的
window_.hidden = NO;
[window_ addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(topWindowClick)]];
});
} + (void)topWindowClick
{
// 主窗口
UIWindow *window = [UIApplication sharedApplication].keyWindow; // 查找主窗口中的所有scrollView
[self findScrollViewsInView:window];
} /**
* 查找view中的所有scrollView
*/
+ (void)findScrollViewsInView:(UIView *)view
{
// 利用递归查找所有的子控件
for (UIView *subview in view.subviews) {
[self findScrollViewsInView:subview];
} if (![view isKindOfClass:[UIScrollView class]]) return; // 判断是否跟window有重叠
if (![view intersectWithView:[UIApplication sharedApplication].keyWindow]) return;
// CGRect windowRect = [UIApplication sharedApplication].keyWindow.bounds;
// CGRect viewRect = [view convertRect:view.bounds toView:nil];
// // 跟window不重叠
// if (!CGRectIntersectsRect(windowRect, viewRect)) return; // 如果是scrollView
UIScrollView *scrollView = (UIScrollView *)view; // 修改offset
CGPoint offset = scrollView.contentOffset;
offset.y = - scrollView.contentInset.top;
[scrollView setContentOffset:offset animated:YES]; // [scrollView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:YES];
}
@end
判断两个控件在同一个Window上是否有重叠的更多相关文章
- form-line 样式 让 两个控件在同一个水平位置
<div class="row"> <div> <label class="form-inline">参加单位:<in ...
- .Net平台Winform两个ComboBox控件绑定同一个数据源
今天WINFROM编程遇到这么一个问题:是有关WINFORM中两个comboBox控件绑定同一个数据源的问题,在窗体的界面上有两个comboBox,我在Form1_Load中对他们做了数据绑定(具体代 ...
- 样式:让div里的两个控件在一行的操作
table的td里如果放一个text,希望在右侧再放一个按钮,让这两个控件在一行,但是放了之后总是底部不能对齐,这样的话,加上下边这句样式就可以了 position:relative; top:17p ...
- Android两个控件叠在一起,如何让被挡住的控件显示出来
Android两个控件叠在一起,如何让被挡住的控件显示出来 问题 : 两个控件叠在一起,如何让被挡住的控件显示出来? 比如A,B两个控件,A被B挡住,目前A要显示出来,B不能被隐藏,A的高度只有那么一 ...
- @Html.CheckBoxFor为何输出两种控件
在MVC中当使用@Html.CheckBoxFor时表单上会产生两种控件checkbox和hidden,比如: @Html.CheckBoxFor(model => model.IsTop) 对 ...
- 9.2.1 .net framework下的MVC 控件的封装(上)
在写.net core下mvc控件的编写之前,我先说一下.net framework下我们MVC控件的做法. MVC下控件的写法,主要有如下三种,最后一种是泛型的写法,mvc提供的控件都是基本控件. ...
- [WPF]使用CheckAccess检测是否在控件的ui线程上执行
private void Parallel(object sender, RoutedEventArgs e) { Task.Run(() => ChangeColour(Brushes.Red ...
- 在此页上的ActiveX控件和本页上的其他部分的交互可能不安全,你想允许这种交互吗
转自 http://www.cnblogs.com/zdxster/archive/2011/01/27/1945868.html 在EOS6的项目中,如果采用VC++开发的ActiveX,那么第一次 ...
- Dbgrid控件多重选择的怪问题。BookMarkList,BookMark,使用书签,用的ADOQuery控件。100分送上,急阿!!!请高手帮忙!
Dbgrid控件多重选择的怪问题.BookMarkList,BookMark,使用书签,用的ADOQuery控件.100分送上,急阿!!!请高手帮忙! ( 积分: 100 )<br />p ...
随机推荐
- mybatis-3 Dynamic SQL
Dynamic SQL One of the most powerful features of MyBatis has always been its Dynamic SQL capabilitie ...
- Swoole学习(七)Swoole之异步TCP服务器的创建
环境:Centos6.4,PHP环境:PHP7 <?php //创建TCP服务器 /** * $host 是swoole需要监听的ip,如果要监听本地,不对外服务,那么就是127.0.0.1;如 ...
- Zabbix 关联onealert实现电话报警
Zabbix 关联onealert实现电话报警 系统环境:Linux Centos 7.4 应用版本:Zabbix 3.0.22 OneAlert官方地址:http://www.onealert.co ...
- 如何用纯 CSS 创作单元素点阵 loader
效果预览 在线演示 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览.https://codepen.io/comehope/pen/YvBvBr 可交互视频 此 ...
- linux ftp 简单搭建
1.安装 yum install vsftpd 2.重启服务 /sbin/service vsftpd restartShutting down vsftpd: [ OK ]Starting vsft ...
- ArchLinux基本系统到XFCE4桌面搭建
Keep It Simple, Stupid 这是ArchLinux的哲学,更是一种人生哲学 好久没用linux了,这段时间因为一点点"破坏性"需求重新拾起linux用了一把 ...
- ASP.NET OAuth Authorization - Difference between using ClientId and Secret and Username and Password
What I don't fully understand is the use of ClientId and Secret vs Username and Password. The code ...
- C# Programming Guide-->Statements, Expressions, and Operators-->Anonymous Functions
C# Programming Guide Anonymous Functions Lambda Expressions Anonymous Methods In versions of C# befo ...
- du,df 磁盘管理
du会把指定目录下所有文件.目录.目录下的文件都统计.是建立在文件系统能看到的的确确是有这样一些文件的基础上的.也就是说我们能在文件系统里面看到的文件才会被du统计. df命令可以获取硬盘被占用了多少 ...
- Java_SQL_类型对应_资料
1.http://argel-lj.iteye.com/blog/1183123 2.http://www.fx114.net/qa-119-110105.aspx JDBC 的"类型&qu ...