2

このビデオのようなカードを開く必要があるアプリを開発しています

https://www.youtube.com/watch?v=srnRuhFvYl0&feature=youtu.be

カードの最初の面 カードの 3 番目の面 カードの裏面 カードの 4 番目の面

私はグーグルで検索しましたが、この機能のコードは見つかりませんでした。

グリーティング カードには 4 つの面があります。Just Wink アプリのようにタップまたはタッチすると、アニメーションまたは UIGesturerecognizer によってグリーティング カードのすべての面を表示する必要があります。

アイデアやサンプルコードを提案していただければ幸いです。

"前もって感謝します"

4

1 に答える 1

4

私はあなたのためにこのコードを書きました。

*これを.pchファイルに入れます

DEGREES_TO_RADIANS(d) を定義 (d * M_PI / 180)

QuartzCore フレームワークを追加してインポートすることを忘れないでください*

    #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];
        }];
    }

これがあなたを助けることを願っています。

于 2013-09-03T10:09:08.677 に答える