详解iOS开发中的转场动画和组动画以及UIView封装动画

2020-01-14 17:05:03于丽

    
    //2.添加核心动画
    [self.customView.layer addAnimation:anima forKey:nil];
}

-(void)animationDidStart:(CAAnimation *)anim
{
    //打印动画块的位置
//    NSLog(@"动画开始执行前的位置:%@",NSStringFromCGPoint(self.customView.center));
    NSLog(@"动画开始执行前的位置:%@",NSStringFromCGPoint( self.customView.layer.position));
}
-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
    //打印动画块的位置
    NSLog(@"动画执行完毕后的位置:%@",NSStringFromCGPoint( self.customView.layer.position));
}

@end


打印结果:

 

详解iOS开发中的转场动画和组动画以及UIView封装动画

2、block动画

(1).简单说明

复制代码
+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion
参数解析:

 

duration:动画的持续时间

delay:动画延迟delay秒后开始

options:动画的节奏控制

animations:将改变视图属性的代码放在这个block中

completion:动画结束后,会自动调用这个block

转场动画

复制代码
+ (void)transitionWithView:(UIView *)view duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion
参数解析:

 

duration:动画的持续时间

view:需要进行转场动画的视图

options:转场动画的类型