Swift and swiftcode
Swift-use CATransform3DMakeRotation to achieve page turning
Effect
Source code
Https://github.com/YouXianMing/Swift-Animations
/// Pageflippolictcontroller. swift // Swift-Animations // Created by YouXianMing on 16/8/22. // Copyright©2016 YouXianMing. All rights reserved. // import UIKitclass PageFlipEffectController: NormalTitleViewController {private var math: Math! = Math (pointA: CGPointMake (0, 0), pointB: CGPointMake (Width (), 180) private var layer: CALayer! Override func setup () {super. setup () let image = UIImage (named: "pic_1") let size = Math. ResetFromSize (image ?. Size )!, WithFixedWidth: Width ()/2.0) layer = CALayer () layer. anchorPoint = CGPointMake (1.0, 0.5) layer. frame = CGRectMake (0, 0, Width ()/2, size. height) layer. allowsEdgeAntialiasing = true layer. position = CGPointMake (Width ()/2, contentView !. MiddleY) layer. contents = image ?. CGImage layer. borderColor = UIColor. blackColor (). CGColor layer. borderWidth = 3.0 layer. masksToBounds = true layer. transform = CATransform3DMakeRotation (Math. radianFromDegree (0), 0, 1, 1) contentView ?. Layer. addSublayer (layer) let panGesture = UIPanGestureRecognizer (target: self, action: # selector (pageflippolictcontroller. handlePan) view. addGestureRecognizer (panGesture)} @ objc private func handlePan (sender: UIPanGestureRecognizer) {let curPoint = sender. locationInView (view) let x = curPoint. x // initialize the 3D transformation and obtain the default value var perspectiveTransform = CATransform3DIdentity // view perspectiveTransform. m34 =-1. 0/2000.0 // space rotation perspectiveTransform = CATransform3DRotate (perspectiveTransform, Math. radianFromDegree (x * math. k), 0, 1, 0) CATransaction. setDisableActions (true) layer. transform = perspectiveTransform layer. contents = UIImage (named: x & gt; = Width ()/2.0? "Pic_2": "pic_1 ")?. CGImage if sender. state =. ended {// initialize the 3D transform and obtain the default value var perspectiveTransform = CATransform3DIdentity // view perspectiveTransform. m34 =-1.0/2000.0 // space rotation perspectiveTransform = CATransform3DRotate (perspectiveTransform, Math. radianFromDegree (x & gt; = Width ()/2.0? 180: 0), 0, 1, 0) CATransaction. setDisableActions (false) layer. transform = perspectiveTransform }}}