码迷,mamicode.com
首页 > 其他好文 > 详细

CATransform3D动画教程

时间:2015-10-11 21:33:09      阅读:233      评论:0      收藏:0      [点我收藏+]

标签:

理论知识网上太多,现在直接甩上一个效果~请各路大神指点~

拖动效果如图:

技术分享

#define APPWITH [UIScreen mainScreen].bounds.size.width
#define APPHEIGHT [UIScreen mainScreen].bounds.size.height

#import "ViewController.h"

@interface ViewController ()
{
    UIImageView  *_imageBg;
}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _imageBg = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 150, 250)];
    _imageBg.image = [UIImage imageNamed:@"11.jpg"];
    _imageBg.layer.cornerRadius = 5.0f;
    _imageBg.clipsToBounds = YES;
    [self.view addSubview:_imageBg];
    
    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(imageActionWithPan:)];
    [self.view addGestureRecognizer:pan];
    _imageBg.userInteractionEnabled = YES;
}


- (void)imageActionWithPan:(UIPanGestureRecognizer *)pan{
    CGPoint point = [pan locationInView:self.view];
    if (pan.state == UIGestureRecognizerStateChanged) {
        CGFloat xx = MIN(0.1, MAX(-0.1, (point.x - (APPWITH/2)) / (APPWITH/2)));
        CGFloat yy = MIN(0.1, MAX(-0.1, (point.y - (APPHEIGHT/2)) / (APPHEIGHT/2)));
        _imageBg.layer.transform = [self transform3DReturnM34:(- 1 / 500.0) xx:xx yy:yy];

    }
    //恢复
    if (pan.state == UIGestureRecognizerStateEnded)
    {
        [UIView animateWithDuration:0.5 animations:^{
            _imageBg.layer.transform = CATransform3DIdentity;
        }];
    }
}


- (CATransform3D)transform3DReturnM34:(CGFloat)m34  xx:(CGFloat)xx yy:(CGFloat)yy{
    CATransform3D trans = CATransform3DIdentity;
    trans.m34 = m34;
    trans = CATransform3DRotate(trans, M_PI  * xx, 0, 1, 0);
    trans = CATransform3DRotate(trans, M_PI  * yy, -1, 0, 0);
    return trans;
}
@end

 

CATransform3D动画教程

标签:

原文地址:http://www.cnblogs.com/yang99/p/4870024.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!