UIActivityIndicatorView添加到UIButton上并响应事件
spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
[spinner startAnimating];
[spinner setUserInteractionEnabled:NO]; // setting UserInteractionEnable to NO, any touch events are forwarded to the superview (the button)
spinner.center = CGPointMake(20, 18);
[self addSubview:spinner];
原文:地址:https://coderwall.com/p/4fydiq/uiactivityindicatorview-over-an-uibutton
Did you know that putting an UIActivityIndicatorView over a UIButton, all touch events are blocked by the spinner?
If you do the same with a UILabel or UIImageView, all events are forwarded to the button (its superview), like I (and you) expect. But with UIActivityIndicatorView this is not the behaviour you get. All these classes are extensions of UIView, so why they work differently?
The key difference is that the UIActivityIndicatorView is animated. When you have an animated view, iOS changes its userInteractionEnabled property to YES to prevent interactions (and interruptions) from the user with that view, during the animation phase.
How to fix that? Just set userInteractionEnabled to NO on the spinner, so all the touch events are forwarded again to the spinner superview (the button in my case) and everything works like I expect.
Here is the example code
spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
[spinner startAnimating];
[spinner setUserInteractionEnabled:NO]; // setting UserInteractionEnable to NO, any touch events are forwarded to the superview (the button)
spinner.center = CGPointMake(20, 18);
[self addSubview:spinner];
UIActivityIndicatorView添加到UIButton上并响应事件的更多相关文章
- 「iOS造轮子」之UIButton 用Block响应事件
俗语说 一个不懒的程序员不是好程序员 造轮子,也只是为了以后更好的coding. coding,简易明了的代码更是所有程序员都希望看到的 无论是看自己的代码,还是接手别人的代码 都希望一看都知道这代码 ...
- UIImageView中的UIButton不响应事件解决方案
如下: CGRect imageRect = (CGRect){, , , }; UIImageView *imageView = [[[UIImageView alloc] initWithFram ...
- 解决UIButton 连续点击重复响应事件问题
经常会遇到重复点击某个按钮 事件被响应多次的情景, 有时候可能对程序本身并没有什么影响 , 可有时候偏偏需要限制button响应事件直接的间隔 . 方法一 : 标记 1 . 利用空闲enable属性来 ...
- 从uibutton的点击谈谈ios的响应事件
最近在做一个项目,接连遇到两个关于点击事件的问题. 1.点击button不能响应事件的. 2.子view的frame超出了父view的容器大小,也不能响应点击事件. 效果图如右: 1.第一张图中的弹出 ...
- 文字添加响应事件,js动态加载CSS, js弹出DIV
文字添加响应事件,js动态加载CSS, js弹出DIV <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN&qu ...
- html .css 实现图片滑动和自动播放特效移动端 HTML 5中添加了以touch 开头的事件
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <meta ...
- JVM上的响应式流 — Reactor简介
强烈建议先阅读下JVM平台上的响应式流(Reactive Streams)规范,如果没读过的话. 官方文档:https://projectreactor.io/. 响应式编程 作为响应式编程方向上的第 ...
- JVM平台上的响应式流(Reactive Streams)规范
// Reactive Streams // 响应式流是一个倡议,用来为具有非阻塞后压的异步流处理提供一个标准.大家努力的目标集中在运行时环境(JVM和JavaScript)和网络协议上. 注:响应式 ...
- 屏蔽响应事件继续向父视图传递的category
屏蔽响应事件继续向父视图传递的category 这篇教程是上一篇教程的升级版,将复杂的代码封装成了category,更便于使用:) 效果: 源码: UIGestureRecognizer+EnvetI ...
随机推荐
- C#堆栈讲解
1:栈就是堆栈,因为堆和堆栈这样说太拗口了,搞得像绕口令,所以有些时候就把堆栈简称为栈.堆和栈,你看这又多舒服.但无论什么时候,堆栈都不等于堆和栈,必须说,堆和栈或者堆和堆栈. 2:值类型变量和引用类 ...
- ajax请求后台,返回json格式数据,模板!
添加一个用户的时候,需要找出公司下所有的部门,和相应部门下的角色,利用ajax请求,实现联动技术.将返回的json格式数据,添加到select标签下. <script type="te ...
- SQL server 中的dbo、guest
dbo database owner 数据库的创建者,创建该对象的用户. guest 顾客 能够访问数据库中对象的数据, 要求dbo分配权限给guest, 一般给他查看的权限select 数据库所有者 ...
- 安装SQL Server驱动到Maven仓库[转]
from:http://raysen.blog.51cto.com/324335/1159232 Maven does not directly support some libraries, lik ...
- Daas
联想到这些年遇到的各种客户使用桌面虚拟化的场景,深有感触.桌面虚拟化技术并不一定适合所有的用户和场景,也不仅仅只是技术方面的问题.加强安全的方法有千万种,为何此客户情守桌面虚拟化呢?某客户已经规模化实 ...
- 【转】UVa Problem 100 The 3n+1 problem (3n+1 问题)——(离线计算)
// The 3n+1 problem (3n+1 问题) // PC/UVa IDs: 110101/100, Popularity: A, Success rate: low Level: 1 / ...
- Win7系统上配置使用Intellij Idea 13的SVN插件
Win7系统上配置使用Intellij Idea 13的SVN插件 http://blog.csdn.net/jeepxiaozi/article/details/39856081
- DBA日常SQL之查询数据库运行状况
,) Day, ,),,)) H00, ,),,)) H01, ,),,)) H02, ,),,)) H03, ,),,)) H04, ,),,)) H05, ,),,)) H06, ,),,)) H ...
- LINUX常用配置及命令
一. Fedora系统配置 1. [设置网卡IP] 步骤如下: 1) 用root用户登陆,打开/etc/sysconfig/network-scripts/ifcfg-eth0文 ...
- css3写出0.5px的边框
一说到0.5px的边框,我们一般认为是不行的,因为在ps中0.5px的线也是做不出来的,这个计算机的像素有关系. 废话不多说了,0.5px 其实用的是css3新特性,box-shadow:阴影设置 代 ...