【动画一般属性】
@interface UIView(UIViewAnimation)
+ (void)beginAnimations:(NSString *)animationID context:(void *)context;
+ (void)commitAnimations;
+ (void)setAnimationDelegate:(id)delegate; //
+ (void)setAnimationWillStartSelector:(SEL)selector; //
+ (void)setAnimationDidStopSelector:(SEL)selector; //
+ (void)setAnimationDuration:(NSTimeInterval)duration; // default = 0.2
+ (void)setAnimationDelay:(NSTimeInterval)delay; // default = 0.0
+ (void)setAnimationStartDate:(NSDate *)startDate; // default = now
[UIView beginAnimations:@"view flip" context:nil];//标记需要动画
[UIView setAnimationDuration:1]; //设置持续时间
[UIView setAnimationDelay:1];//延迟
// [UIView setAnimationStartDate:[NSDate dateWithTimeIntervalSinceNow:2]];//开始时间,具体研究NSDate
[UIView setAnimationWillStartSelector:@selector(animationStart)];//动画开始时
[UIView setAnimationDidStopSelector:@selector(animationStop)];//动画结束时
[UIView setAnimationDelegate:self];
<pre name="code" class="objc"> <pre name="code" class="objc"> [redView addSubview:greenView]; //父视图添加子视图
[UIView commitAnimations]; //提交动画
【动画效果,默认四个】
+ (void)setAnimationTransition:(UIViewAnimationTransition)transition forView:(UIView *)view cache:(BOOL)cache;
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:redView cache:YES];//父视图,添加动画效果
/*
typedef NS_ENUM(NSInteger, UIViewAnimationTransition) {
UIViewAnimationTransitionNone, //无
UIViewAnimationTransitionFlipFromLeft, //左边翻转
UIViewAnimationTransitionFlipFromRight, //右边翻转
UIViewAnimationTransitionCurlUp, //向上翻页
UIViewAnimationTransitionCurlDown, //向下翻页
};
*/
【动画速度变化】
+ (void)setAnimationCurve:(UIViewAnimationCurve)curve;
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
/*
typedef NS_ENUM(NSInteger, UIViewAnimationCurve) {
UIViewAnimationCurveEaseInOut, // 先加速,再减速
UIViewAnimationCurveEaseIn, // 加速
UIViewAnimationCurveEaseOut, // 减速
UIViewAnimationCurveLinear // 匀速
};
*/
【动画次数与开始结束的效果】
+ (void)setAnimationRepeatCount:(float)repeatCount; // default = 0.0.
+ (void)setAnimationRepeatAutoreverses:(BOOL)repeatAutoreverses; // default = NO.
+ (void)setAnimationBeginsFromCurrentState:(BOOL)fromCurrentState; // default = NO.
[UIView setAnimationRepeatCount:3]; //动画次数
[UIView setAnimationRepeatAutoreverses:YES]; //一次动画结束,回到原来的状态
[UIView setAnimationBeginsFromCurrentState:YES];
/*当YES时:当上一次动画正在执行中,那么当下一个动画开始时,上一次动画的当前状态将成为下一次动画的开始状态。
当NO时:当上一个动画正在执行中,那么当下一个动画开始时,上一次动画需要先恢复到完成时的状态,然后在开始执行下一次动画。
*/
【是否使用动画效果】
+ (void)setAnimationsEnabled:(BOOL)enabled; //
+ (BOOL)areAnimationsEnabled;
+ (void)performWithoutAnimation:(void (^)(void))actionsWithoutAnimationNS_AVAILABLE_IOS(7_0);
//仅仅是动画是否可用,在动画中被改变的UI对象依然是起作用的。仅仅是动画效果被禁用了。(没验证,有什么用??待研究)
[UIView setAnimationsEnabled:YES];
if ([UIView areAnimationsEnabled]) {
NSLog(@"yes");
}else{
NSLog(@"no");
}
[UIView performWithoutAnimation:^{
sleep(3);
[greenView setFrame:CGRectMake(111, 111, 111,111)];
}];//先检查动画当前是否启用,然后禁止动画,执行块语句,最后重新启用动画。
@end