Let arrowimage = Uiimageview(Image: UIImage(named: "Machine_arrow")!. Imagewithrenderingmode(. Alwaystemplate))
let Arrowbutton = UIButton(frame: cgrectmake, arrowimage. Bounds. Width, arrowimage. Bounds. Height))
Arrowbutton. addsubview(arrowimage)
Arrowbutton. addTarget(self, action: #selector(btnclicked(_: Event:)), forControlEvents:. touchupinside)
Check the position of the user when the button is clicked and forward the event to the corresponding accessorytapped event
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)
}
// This way, the Accessorybuttontappedforrowwithindexpath method of UITableView is triggered and a indexpath is obtained parameters. With this indexpath parameter, we can distinguish between which of the many buttons the attachment button has a touch event:
func TableView (tableView: uitableview, Accessorybuttontappedforrowwithindexpath Indexpath: Nsindexpath) {
let idx = Indexpath. Row
// Add your own logic here
print(idx)
// Click the arrow to rotate
rotat()
// rotatearrow()
}
// rotate animation one
func Rotat () {
// Create a rotation animation
let anim = cabasicanimation(keypath: "transform.rotation")
// rotation angle
Anim.tovalue = 1 * m_pi
// rotate the time required to specify the angle
Anim.Duration = 1
// rotation Repeat Count
Anim.repeatcount = maxfloat
// animation does not remove after execution
Anim.removedoncompletion = true
// add animations to the Laye of the view
arrowimage. Layer. Addanimation(Anim, Forkey: nil)
// Cancel animation
arrowimage. Layer. Removeallanimations()
// This is an animation of the direction of rotation
UIView. Animatewithduration(0.2) {(), Void in
// Specify a rotation angle of 180°
self. Arrowimage. Transform = cgaffinetransformrotate(self. Arrowimage. Transform, cgfloat(m_pi))
}
}
rotate an animation two
func Rotatearrow () {
UIView. Animatewithduration(0.3, animations: {[weak self] ()--( ) in
if let selfie = self {
Selfie. arrowimage. Transform = cgaffinetransformrotate(selfie. Arrowimage. Transform, cgfloat(m_pi/ +))
}
})
}
Swift-click the arrow to rotate