Swift - 点击箭头旋转
let arrowImage = UIImageView(image: UIImage(named: "Machine_arrow")!.imageWithRenderingMode(.AlwaysTemplate))
let arrowButton = UIButton(frame: CGRectMake(700, 20, arrowImage.bounds.width, arrowImage.bounds.height))
arrowButton.addSubview(arrowImage)
arrowButton.addTarget(self, action: #selector(btnClicked(_:event:)), forControlEvents: .TouchUpInside)
// 检查用户点击按钮时的位置,并转发事件到对应的accessorytapped事件
func btnClicked(sender: UIButton, event: AnyObject) {
let touches = event.allTouches()! as NSSet
let touch = touches.anyObject() as! UITouch
let currentTouchPosition = touch.locationInView(selectTable)
let indexPath: NSIndexPath = selectTable.indexPathForRowAtPoint(currentTouchPosition)!
tableView(selectTable, accessoryButtonTappedForRowWithIndexPath: indexPath)
}
// 这样,UITableView的accessoryButtonTappedForRowWithIndexPath方法会被触发,并且获得一个indexPath 参数。通过这个indexPath 参数,我们可以区分到底是众多按钮中的哪一个附件按钮发生了触摸事件:
func tableView(tableView: UITableView, accessoryButtonTappedForRowWithIndexPath indexPath: NSIndexPath) {
let idx = indexPath.row
//在这里加入自己的逻辑
print(idx)
// 点击箭头旋转
rotat()
// rotateArrow()
}
// 旋转动画一
func rotat() {
//创建旋转动画
let anim = CABasicAnimation(keyPath: "transform.rotation")
//旋转角度
anim.toValue = 1 * M_PI
//旋转指定角度需要的时间
anim.duration = 1
//旋转重复次数
anim.repeatCount = MAXFLOAT
//动画执行完后不移除
anim.removedOnCompletion = true
//将动画添加到视图的laye上
arrowImage.layer.addAnimation(anim, forKey: nil)
//取消动画
arrowImage.layer.removeAllAnimations()
//这个是旋转方向的动画
UIView.animateWithDuration(0.2) { () -> Void in
//指定旋转角度是180°
self.arrowImage.transform = CGAffineTransformRotate(self.arrowImage.transform, CGFloat(M_PI))
}
}
// 旋转动画二
func rotateArrow() {
UIView.animateWithDuration(0.3, animations: {[weak self] () -> () in
if let selfie = self {
selfie.arrowImage.transform = CGAffineTransformRotate(selfie.arrowImage.transform, 180 * CGFloat(M_PI/180))
}
})
}
Swift - 点击箭头旋转的更多相关文章
- Swift - 点击事件奇偶次判断
// 按钮点击事件 func onTouchUpInside() { struct touchUpInside { static var count: Int = 0 } touchUpInside. ...
- swift 点击button改变其内填充图片,达到选中的效果
先看下效果: 点击后: 实现:在页面拖一个button,然后在所在页面声明其变量和一个点击事件 声明: @IBOutlet weak var BtnZiDong: UIButton! 点击事件函数: ...
- Swift - 点击输入框外部屏幕关闭虚拟键盘
我们如果把文本框的Return Key设置成Done,然后在storyboard中将文本框的Did End On Exit事件在代码里进行关联.同时关联代码里调用文本框的resignFirstResp ...
- Swift实时画箭头的实现
iOS上实现画箭头,如果是指定了坐标点,那是很简单的,但如果需要做到实时绘制,就需要计算一下了 需求: 在白板上,根据手势落下点和移动点,实时绘制一条箭头直线(如下图) 实现代码: /// 获取箭头的 ...
- css3+jq--小箭头旋转180度案例
html: <aside class="tea_getBtn"> <div class="w"> <span class=&quo ...
- iOS手势操作,拖动,轻击,捏合,旋转,长按,自定义(http://www.cnblogs.com/huangjianwu/p/4675648.html)
1.UIGestureRecognizer 介绍 手势识别在 iOS 中非常重要,他极大地提高了移动设备的使用便捷性. iOS 系统在 3.2 以后,他提供了一些常用的手势(UIGestureReco ...
- jq 获取下一个兄弟原素 下拉箭头旋转
$('.weui-cells__title').on("click", function(e,rr){ isshow=$(this).attr('isshow') if(issho ...
- jQuery和css3控制箭头丝滑旋转
问题: 我们经常会遇见点击一个小三角使之丝滑的旋转180度上下旋转,怎么实现呢,需要css3搭配jq 来处理 如图:1.点击前 2.点击后(效果丝滑旋转) 1.html ...
- 侧边栏下拉时箭头的旋转动画(treeView控件)
//点击菜单时箭头旋转 let treeView = document.getElementsByClassName("treeview");//let解决闭包问题 let las ...
随机推荐
- HTML坦克大战学习01
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <t ...
- Flume1.5.0入门:安装、部署、及flume的案例
转自:http://www.aboutyun.com/thread-8917-1-1.html 问题导读1.什么是flume2.flume的官方网站在哪里?3.flume有哪些术语?4.如何配置flu ...
- eclipse的Maven项目pom.xml错误信息提示missingxxxjar解决方案
今天在学习的时候需要用到maven工程,当时找完所依赖的包的三要素就开始下载了,写完pom.xml需要一段时间下载这些jar包,就躺在一边等了.可能是笔记本有节能功能这个原因导致我醒来时断网发现满屏m ...
- e578. Setting the Clipping Area with a Shape
This example demonstrates how to set a clipping area using a shape. The example sets an oval for the ...
- MySQL索引覆盖
什么是“索引覆盖”? 简单来的说,就是让查询的字段(包括where子句中的字段),都是索引字段.索引覆盖的好处是什么?好处是极大的.极大的.极大的提高查询的效率!重要的说三遍! 特别说明: 1.whe ...
- CentOS服务器上搭建Gitlab安装步骤、中文汉化详细步骤、日常管理以及异常故障排查
一, 服务器快速搭建gitlab方法 可以参考gitlab中文社区 的教程centos7安装gitlab:https://www.gitlab.cc/downloads/#centos7centos6 ...
- Getting SharePoint objects (spweb, splist, splistitem) from url string
You basically get anything in the object model with one full url: //here is the site for the url usi ...
- 如何在word文档中添加mathtype加载项
MathType是强大的数学公式编辑器,通常与office一起使用,mathtype安装完成后,正常情况下会在word文档中的菜单中自动添加mathtype加载项,但有时也会出现小意外,mathtyp ...
- OpenCV学习:OpenCV源码编译(vc9)
安装后的OpenCV程序下的build文件夹中,只找到了vc10.vc11和vc12三种编译版本的dll和lib文件,需要VS2010及以上的IDE版本,而没有我们常用的VS2008版本. 于是,需要 ...
- css文字超出自动显示省略号
只针对单行文本有效: 01.针对块状元素 ul li{ width: 180px; text-overflow: ellipsis; white-space: nowrap;/*禁止自动换行*/ ov ...