Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>(void)animateViewWith3DCurrentView:(UIView *)currentView withPoing:(CGPoint)movePoint { //flip the view by 180 degrees in its place first. currentView.layer.transform = CATransform3DRotate(currentView.layer.transform,myRotationAngle(180), 0, 1, 0); //set the anchor point so that the view rotates on one of its sides. currentView.layer.anchorPoint = CGPointMake(0.5, 0.5); //Set up scaling CABasicAnimation *resizeAnimation = [CABasicAnimation animationWithKeyPath:kResizeKey]; //we are going to fill the screen here. So 423,337 [resizeAnimation setToValue:[NSValue valueWithCGSize:CGSizeMake(423, 337)]]; resizeAnimation.fillMode = kCAFillModeForwards; resizeAnimation.removedOnCompletion = NO; // Set up path movement UIBezierPath *movePath = [UIBezierPath bezierPath]; //the control point is now set to centre of the filled screen. Change this to make the path different. // CGPoint ctlPoint = CGPointMake(0.0, 0.5); CGPoint ctlPoint = CGPointMake(1024/2, 768/2); //This is the starting point of the animation. This should ideally be a function of the frame of the view to be animated. Hardcoded here. // Set here to get the accurate point.. [movePath moveToPoint:movePoint]; //The anchor point is going to end up here at the end of the animation. [movePath addQuadCurveToPoint:CGPointMake(1024/2, 768/2) controlPoint:ctlPoint]; CAKeyframeAnimation *moveAnim = [CAKeyframeAnimation animationWithKeyPath:kPathMovement]; moveAnim.path = movePath.CGPath; moveAnim.removedOnCompletion = YES; // Setup rotation animation CABasicAnimation* rotateAnimation = [CABasicAnimation animationWithKeyPath:kRotation]; //start from 180 degrees (done in 1st line) CATransform3D fromTransform = CATransform3DMakeRotation(myRotationAngle(180), 0, 1, 0); //come back to 0 degrees CATransform3D toTransform = CATransform3DMakeRotation(myRotationAngle(0), 0, 1, 0); //This is done to get some perspective. CATransform3D persp1 = CATransform3DIdentity; persp1.m34 = 1.0 / -3000; fromTransform = CATransform3DConcat(fromTransform, persp1); toTransform = CATransform3DConcat(toTransform,persp1); rotateAnimation.toValue = [NSValue valueWithCATransform3D:toTransform]; rotateAnimation.fromValue = [NSValue valueWithCATransform3D:fromTransform]; //rotateAnimation.duration = 2; rotateAnimation.fillMode = kCAFillModeForwards; rotateAnimation.removedOnCompletion = NO; // Setup and add all animations to the group CAAnimationGroup *group = [CAAnimationGroup animation]; [group setAnimations:[NSArray arrayWithObjects:moveAnim,rotateAnimation, resizeAnimation, nil]]; group.fillMode = kCAFillModeForwards; group.removedOnCompletion = NO; group.duration = 0.7f; group.delegate = self; [group setValue:currentView forKey:kGroupAnimation]; [currentView.layer addAnimation:group forKey:kLayerAnimation]; } </code></pre>
 

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