animation = YES/NO 還在用這個(gè)玩意?
?
?
?
動(dòng)畫(huà)看起來(lái)都很牛X吧,其實(shí)用我們的UIKit庫(kù)也可以實(shí)現(xiàn)一些動(dòng)畫(huà)的,
雖然不能向CG那么厲害,但是在項(xiàng)目里加上一些小小的動(dòng)畫(huà),
就瞬間可以讓你的項(xiàng)目高大上不少.
如果之前沒(méi)接觸過(guò)那也沒(méi)關(guān)系,先上一張需求圖;
效果圖
這個(gè)需求,同樣不是很復(fù)雜,實(shí)現(xiàn)界面的思路大概就是:
底層一個(gè)兩倍屏寬的底視圖添加到我們?cè)镜腷ackView上;
創(chuàng)建兩個(gè)與屏幕寬高相同的view把他添加到backView上;
通過(guò)Button的觸發(fā)方法.在改變backView的位置情況下,
圍繞button中心點(diǎn)環(huán)繞旋轉(zhuǎn).
再來(lái)一張效果圖;
效果圖
直接上動(dòng)畫(huà)代碼:
- (void)rotate:(id)sender {
//
self.btnSelectCount += 1;
if (self.btnSelectCount%2==0) {
CGPoint accountCenter = self.mainView.center;
self.mainView.center = accountCenter;
accountCenter.x -= WIDTH;
[UITextField animateWithDuration:0.5 animations:^{
self.mainView.center = accountCenter;
} completion:nil];
}else{
CGPoint accountCenter = self.mainView.center;
self.mainView.center = accountCenter;
accountCenter.x += WIDTH;
[UIView animateWithDuration:0.5 animations:^{
self.mainView.center = accountCenter;
} completion:nil];
}
//
if (flag) {
[UIView animateWithDuration:0.5 animations:^{
self->_imageView.transform = CGAffineTransformMakeRotation(-M_PI);
} completion:^(BOOL finished) {
self->flag = NO;
}];
}
else {
[UIView animateWithDuration:0.5 animations:^{
self->_imageView.transform = CGAffineTransformMakeRotation(0.0001);
} completion:^(BOOL finished) {
self->flag = YES;
}];
}
}
具體Demo里面pod了Masonry ;pod文件太大了,pod文件太大沒(méi)一起上傳自己重新pod install 一下就好了;