如何做到在IOS翻转贺卡 [英] How to do Flipping Greeting Card in IOS

查看:148
本文介绍了如何做到在IOS翻转贺卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个应用程序中,我要开一个卡这样的视频

I am developing an app in which I have to open a card like this video

https://www.youtube.com/watch?v= srnRuhFvYl0和放大器;配备= youtu.be




我用Google搜索,但没有发现任何code此功能。

I googled but did not find any code for this functionality.

贺卡有四条边。我需要无论是动画还是UIGesturerecognizer窃听或只是眨眼应用感动就像当查看贺卡的每一面。

Greeting card has four sides. I need to view every side of greeting card either by Animation or UIGesturerecognizer when tapped or touched like in Just Wink App.

中的任何一个提出意见或样本code将AP preciated。

Any one suggest ideas or sample code will be appreciated.

由于提前

推荐答案

我写了这个code你。

*把这个文件.PCH

*Put this in .pch file

和不要忘记添加和进口QuartzCore框架*

and don't forget to add and import QuartzCore framework*

    #import "MyViewController.h"
    #import <QuartzCore/QuartzCore.h>

    @interface MyViewController (){
        CATransform3D intialTransform;
        CATransform3D middelTransform;
        CATransform3D finalTransform;
    }

    @property(nonatomic,strong) UIView *myView1;
    @property(nonatomic,strong) UIView *myView2;

    @end

    @implementation MyViewController

    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self) {
            // Custom initialization
        }
        return self;
    }

    - (void)viewDidLoad
    {
        [super viewDidLoad];

        UIButton *myButton =[[UIButton alloc]initWithFrame:CGRectMake(300, 100, 120, 50)];
        [myButton addTarget:self action:@selector(unfoldGreeting:) forControlEvents:UIControlEventTouchDown];
        [myButton setTitle:@"Unfold" forState:UIControlStateNormal];
        [myButton setBackgroundColor:[UIColor blackColor]];
        [self.view addSubview:myButton];


        _myView1 = [[UIView alloc]initWithFrame:CGRectMake(400, 200, 200, 300)];
        [_myView1 setBackgroundColor:[UIColor redColor]];
        [self.view addSubview:_myView1];

        UILabel *myLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 150, 100, 100)];
        [myLabel setText:@"Happy Birthday"];
        [myLabel setFont:[UIFont fontWithName:@"Arial" size:25]];
        [myLabel setTextColor:[UIColor whiteColor]];
        [myLabel sizeToFit];
        [_myView1 addSubview:myLabel];

        intialTransform = CATransform3DIdentity;
        intialTransform.m34 = 1.0 / -500;
        intialTransform = CATransform3DRotate(intialTransform, DEGREES_TO_RADIANS(70), 1.0f, 0.0f, 0.0f);
        _myView1.layer.transform = intialTransform;

        _myView2 = [[UIView alloc]initWithFrame:CGRectMake(400, 200, 200, 300)];
        [_myView2 setBackgroundColor:[UIColor purpleColor]];
        [self.view addSubview:_myView2];
        _myView2.layer.transform = intialTransform;

        middelTransform = CATransform3DIdentity;
        middelTransform.m34 = 1.0 / -500;
        middelTransform = CATransform3DRotate(middelTransform, DEGREES_TO_RADIANS(70), 1.0f, 0.0f, 0.0f);
        middelTransform = CATransform3DRotate(middelTransform, DEGREES_TO_RADIANS(-100), 0.0f, 1.0f, 0.0f);
        middelTransform = CATransform3DTranslate(middelTransform,116, 0,100);



        finalTransform = CATransform3DIdentity;
        finalTransform.m34 = 1.0 / -500;
        finalTransform = CATransform3DRotate(finalTransform, DEGREES_TO_RADIANS(70), 1.0f, 0.0f, 0.0f);
        finalTransform = CATransform3DRotate(finalTransform, DEGREES_TO_RADIANS(-170), 0.0f, 1.0f, 0.0f);
        finalTransform = CATransform3DTranslate(finalTransform,198, 0,16);



    }

    -(void)unfoldGreeting:(UIButton *)iSender{

        [UIView animateWithDuration:1.0f animations:^{
            _myView2.layer.transform = middelTransform;
        } completion:^ (BOOL iFinished) {
            [UIView animateWithDuration:1.0f animations:^{
            _myView2.layer.transform = finalTransform;
            }completion:nil];
        }];
    }

希望这会帮助你。

这篇关于如何做到在IOS翻转贺卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆