- (void)viewDidLoad {

    [super viewDidLoad];

 UIView *view1 = [[UIView alloc]init];

    [self.view addSubview:view1];

    view1.frame = CGRectMake(100, 400, 100, 100) ;

    view1.backgroundColor = [UIColor redColor];

    view1.layer.anchorPoint = CGPointMake(0.5, 0);

    

    UIView *view2 = [[UIView alloc]init];

    [self.view addSubview:view2];

    view2.frame = CGRectMake(100, 400, 100, 100);

    view2.backgroundColor = [UIColor yellowColor];

    view2.layer.anchorPoint = CGPointMake(0.5, 0);

    self.view2 = view2;

//把view1 和view2换成两个imgageVIew加上图片就可以看到下图的效果啦

 }

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{


    static float degree = 0.f;

    //开始值

    CATransform3D fromValue = CATransform3DIdentity;

    fromValue.m34           = 1.0/ -500;

    fromValue               = CATransform3DRotate(fromValue, degree, 1, 0, 0);


    // 结束值

    CATransform3D toValue   = CATransform3DIdentity;

    toValue.m34             = 1.0/ -500;

    toValue                 = CATransform3DRotate(toValue, -110, 1, 0, 0);


    // 添加3d动画

CABasicAnimation *transform3D = [CABasicAnimation animationWithKeyPath:@"transform"];

    transform3D.duration  = 1.f;

    transform3D.delegate  = self;

    transform3D.fromValue = [NSValue valueWithCATransform3D:fromValue];

    transform3D.toValue   = [NSValue valueWithCATransform3D:toValue];

    self.view2.layer.transform = toValue;

    [transform3D setValue:@"endAnimation" forKey:@"transform3D"];

    [self.view2.layer addAnimation:transform3D forKey:@"endAnimation"];

 

}


新年到了一起拆红包吧

 想要了解更多请关注公众号

新年到了一起拆红包吧


相关文章: