您的位置:首页 > 其它

coreAnimation与viewAnimation

2015-11-22 16:28 253 查看


//
//  ViewController.m
//  CAAnimationAndViewAnimation
//
//  Created by ys on 15/11/22.
//  Copyright (c) 2015年 ys. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIView *blackView;

@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
//    [self diyCACoreAnimation];
//    [self viewAnimation1];
//    [self viewAnimation2];
[self viewAnimation3];

}
/**
*  核心动画的问题在于  1.其直接操作layer层,和view层比不够面向对象.
*                   2.layer的属性均没有改变.图层动画都是假象, 在动画执行过程中, 图层的position属性一直都没有变过
*  因此在实际开发中,除非某些效果难以达到,一般都是使用view实现动画
*/
-(void)diyCACoreAnimation
{
CABasicAnimation *anim = [CABasicAnimation animation];
anim.keyPath = @"position";
anim.toValue = [NSValue valueWithCGPoint:CGPointMake(200, 200)];
anim.duration = 0.5;
anim.removedOnCompletion = NO;
anim.fillMode = kCAFillModeForwards;
anim.delegate = self;
[self.blackView.layer addAnimation:anim forKey:nil];

}

-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
//diyCACoreAnimation动画结束后打印一下发现图层的position属性一直都没有变过
NSLog(@"%@",NSStringFromCGPoint(self.blackView.layer.position));
}

-(void)viewAnimation1
{
[UIView beginAnimations:nil context:nil];
self.blackView.center = CGPointMake(200, 200);
[UIView commitAnimations];
NSLog(@"%@",NSStringFromCGPoint(self.blackView.center));
}

-(void)viewAnimation2
{
[UIView animateWithDuration:1.0 animations:^{
self.blackView.center = CGPointMake(200, 200);
} completion:^(BOOL finished) {
NSLog(@"%@",NSStringFromCGPoint(self.blackView.center));
}];
}

-(void)viewAnimation3
{
[UIView transitionWithView:self.blackView duration:10 options:UIViewAnimationOptionTransitionFlipFromRight animations:^{
} completion:^(BOOL finished) {
}];
}
@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: