1、最簡單,最實用,最常用的[移動動畫]
//移動一個view
---------------------------------------------------------------------------------------------------------------------------------
+(void)MoveView:(UIView *)view To:(CGRect)frame During:(float)time{
// 動畫開始
[UIView beginAnimations:nil context:nil];
// 動畫時間曲線 EaseInOut效果
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
// 動畫時間
[UIView setAnimationDuration:time];
view.frame = frame;
// 動畫結束(或者用提交也不錯)
[UIView commitAnimations];
}
---------------------------------------------------------------------------------------------------------------------------------
適用範圍:
常常出現在ipad項目中,當使用者點擊一個圖片,或者一條資訊,你將彈出一個詳細頁面[detailview],將起始frame初始化為cgrectmake(self.view.frame.size.width/2,self.view.size.height/2, 0, 0),結束位置[frame] ,常用的動畫間隔時間0.4f-0.6f。
[AnimtionTool MoveView:detailview To:frame During:0.5f];
效果,頁面中間將從小到大顯示一個view[detailview]
通常這個View會是放大到全屏,或者半屏大小,然後再點擊後,自動消失。所以這個View會被自義成一個新的View,然後在接收點擊事件後,調用[self removeFromParentView];的方法
2、漸漸顯示一個view,需要在調用此方法的類中重寫此方法
---------------------------------------------------------------------------------------------------------------------------------
/*
- (void)onAnimationComplete:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
if ([animationID isEqualToString: SHOW_VIEW]) {
//do something
} else if ([animationID isEqualToString:HIDDEN_VIEW]) {
//do something
}
}
*/
+(void)ShowView:(UIView *)view To:(CGRect)frame During:(float)time delegate:(id)delegate;{
[UIView beginAnimations:SHOW_VIEW context:nil];
[UIView setAnimationDuration:time];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
if(delegate !=nil &&[delegate respondsToSelector:@selector(onAnimationComplete:finished:context:)]){
[UIView setAnimationDidStopSelector:@selector(onAnimationComplete:finished:context:)];
[UIView setAnimationDelegate:delegate];
}
view.hidden = NO;
view.layer.opacity = 1.0;
view.frame = frame;
[UIView commitAnimations];
}
---------------------------------------------------------------------------------------------------------------------------------
3、漸漸隱藏一個view
---------------------------------------------------------------------------------------------------------------------------------
+(void)HiddenView:(UIView *)view To:(CGRect)frame During:(float)time delegate:(id)delegate{
[UIView beginAnimations:HIDDEN_VIEW context:nil];
[UIView setAnimationDuration:time];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
if(delegate !=nil &&[delegate respondsToSelector:@selector(onAnimationComplete:finished:context:)]){
[UIView setAnimationDidStopSelector:@selector(onAnimationComplete:finished:context:)];
[UIView setAnimationDelegate:delegate];
}
view.frame = frame;
view.layer.opacity = 0.0;
[UIView commitAnimations];
}