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 ...
随机推荐
- 格林威治时间格式(GMT)与普通时间格式的互相转换
GMT --> 普通时间格式: 方法: function GMTToStr(time){ var date = new Date(time) var Str=date.getFullYear() ...
- JS下拉图片Demo3
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- javascript时钟代码 DEMO-002
转载自:http://www.cnblogs.com/Mygirl/archive/2012/03/30/2425832.html 正常时间显示 复制代码 <SCRIPT language=ja ...
- e638. 向剪切板获取和粘贴图像
// If an image is on the system clipboard, this method returns it; // otherwise it returns null. pub ...
- 应当将指针变量用“==”或“!=”与 NULL 比较
应当将指针变量用“==”或“!=”与 NULL 比较. 指针变量的零值是“空”(记为 NULL). 尽管 NULL 的值与 0 相同,但是两者意义不 同. 假设指针变量的名字为 p,它与零值比较的标准 ...
- 在对listctrl的控件进行重载的过程中,GetHeaderCtrl()返回NULL的问题
先谈谈我的问题吧! 在使用listctrl的过程中,我需要在列表头部添加checkbox,实现全选的功能. 经过网上资料的罗列,我找到了一个demo,使用的重绘的方法,在使用的过程中,我发现我的列表头 ...
- Js Object转化为json,json转Object
var obj={x:10,y:50};var t= JSON.stringify(obj);console.log(typeof t);var gg= JSON.parse(t);console.l ...
- iOS 数据压缩与解压
转自: http://blog.csdn.net/dkq972958298/article/details/53321804 在实际开发中,我们经常要对比较大的数据进行压缩后再上传服务器,下面是我在项 ...
- 面试题:谈谈如何优化MYSQL数据库查询
1.优化数据类型 MySQL中数据类型有多种,如果你是一名DBA,正在按照优化的原则对数据类型进行严格的检查,但开发人员可能会选择他们认为最简单的方案,以加快编码速度,或者选择最明显的选择,因此,你可 ...
- mysqldump如何针对某些数据库进行备份?针对某个数据库进行备份?
需求描述: 通过mysqldump工具对mysql服务器中的某几个数据库进行备份. 或者就对其中的一个数据库进行备份. 操作过程: 1.通过--databases参数后面加上数据库的名字进行备份 [m ...