Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use this code sample for review "open card" animation in implementation which work for me. Just insert the code in the new "single view" project and run.</p> <p>ViewController.h</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface ViewController : UIViewController @end </code></pre> <p>ViewController.m</p> <pre><code>#import "ViewController.h" @interface ViewController () @property (strong, nonatomic) UIView *insideView; @property (strong, nonatomic) UIView *pageView; @property (strong, nonatomic) UIView *backPageView; @property (assign, nonatomic) CGRect cardFrame; @end @implementation ViewController - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; if ([touch locationInView:[self view]].x &lt;= CGRectGetMaxX(_cardFrame)) { float dx = ([touch locationInView:[self view]].x - CGRectGetMaxX(_cardFrame)) / _cardFrame.size.width; //create perspective CATransform3D mt = CATransform3DIdentity; mt.m34 = 1.0/-500.; //create rotation CATransform3D open = CATransform3DMakeRotation( -dx * M_PI_2, 0, - 1, 0); //create result transform CATransform3D openTransform = CATransform3DConcat(open, mt); //apply transforms [[_pageView layer] setTransform:openTransform]; [[_backPageView layer] setTransform:openTransform]; } } - (void)viewDidLoad { [super viewDidLoad]; [[self view] setBackgroundColor:[UIColor grayColor]]; //create frame for 2 test views CGFloat size = 200.0; _cardFrame = CGRectMake([[self view] center].x - size / 2, [[self view] center].y - size / 2 , size, size); //lower view _insideView = [[UIView alloc] initWithFrame: _cardFrame]; [_insideView setBackgroundColor:[UIColor redColor]]; //upper view _pageView = [[UIView alloc] initWithFrame:_cardFrame]; [_pageView setBackgroundColor:[UIColor greenColor]]; //upper view back side _backPageView = [[UIView alloc] initWithFrame:_cardFrame]; [_backPageView setBackgroundColor:[UIColor blueColor]]; [[self view] addSubview:_insideView]; [[self view] addSubview:_pageView]; [[self view] insertSubview:_backPageView belowSubview:_pageView]; //get layer of upper view and set needed property CALayer *viewLayer = [_pageView layer]; CALayer *viewBackLayer = [_backPageView layer]; [viewLayer setAnchorPoint:(CGPoint){0.0 , 0.5}]; [viewLayer setFrame:_cardFrame]; [viewLayer setDoubleSided:NO]; [viewBackLayer setAnchorPoint:(CGPoint){0.0 , 0.5}]; [viewBackLayer setFrame:_cardFrame]; //create perspective CATransform3D mt = CATransform3DIdentity; mt.m34 = 1.0/-500.; //create rotation CATransform3D open = CATransform3DMakeRotation(3 * M_PI_4, 0, - 1, 0); //create result transform CATransform3D openTransform = CATransform3DConcat(open, mt); [UIView animateWithDuration:1.0 animations:^ { //close animation [viewLayer setTransform:openTransform]; [viewBackLayer setTransform:openTransform]; } completion:^(BOOL finished) { [UIView animateWithDuration:1.0 animations:^ { //close animation [viewLayer setTransform:CATransform3DIdentity]; [viewBackLayer setTransform:CATransform3DIdentity]; }]; }]; } @end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload