如何在每次点击按钮时旋转视图?
当我尝试:
@IBAction func replaceCurrencies(sender: AnyObject) {
UIView.animateWithDuration(Double(0.5), animations: {
self.arrows.transform = CGAffineTransformMakeRotation(CGFloat(M_PI))
}
}
它只旋转一次。它不会旋转以进行下一次点击。我该如何解决?
答案 0 :(得分:3)
这是因为当你再次按下按钮时,你的视图已经有了这个转换。您需要将其重置为.navbar-fixed {
position:fixed;
top:1;
}
或从当前变换旋转。第二种方式是优选的,因为它不会在旋转之前跳转开始:
var dt = new Date();
var month = new Array();
month[0] = "JAN";
month[1] = "FEB";
month[2] = "MAR";
month[3] = "APR";
month[4] = "MAY";
month[5] = "JUNE";
month[6] = "JULY";
month[7] = "AUG";
month[8] = "SEPT";
month[9] = "OCT";
month[10] = "NOV";
month[11] = "DEC";
var tmonth = dt.getMonth() + 6 <= 11 ? dt.getMonth() + 6 : dt.getMonth() - 6;
var tyear = dt.getMonth() + 6 <= 11 ? dt.getFullYear() : dt.getFullYear() + 1;
var eom = new Date(tyear, tmonth + 1, 0).getDate(); //get last day of the month
var tday = dt.getDate() > eom ? eom : dt.getDate(); //check if the from day of month > last day of month
var frm = dt.getDate() + '-' + month[dt.getMonth()] + '-' + dt.getFullYear().toString().substr(2, 2);
var till = tday + '-' + month[tmonth] + '-' + tyear.toString().substr(2, 2);