首页 技术 正文
技术 2022年11月20日
0 收藏 714 点赞 2,179 浏览 1847 个字

Swift – 用CATransform3DMakeRotation实现翻页效果

Swift – 用CATransform3DMakeRotation实现翻页效果

效果

Swift – 用CATransform3DMakeRotation实现翻页效果

源码

https://github.com/YouXianMing/Swift-Animations

//
// PageFlipEffectController.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(, ), pointB: CGPointMake(Width(), ))
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(, , Width() / , size.height)
layer.allowsEdgeAntialiasing = true
layer.position = CGPointMake(Width() / , contentView!.middleY)
layer.contents = image?.CGImage
layer.borderColor = UIColor.blackColor().CGColor
layer.borderWidth = 3.0
layer.masksToBounds = true
layer.transform = CATransform3DMakeRotation(Math.RadianFromDegree(), , , )
contentView?.layer.addSublayer(layer) let panGesture = UIPanGestureRecognizer(target: self, action: #selector(PageFlipEffectController.handlePan))
view.addGestureRecognizer(panGesture)
} @objc private func handlePan(sender : UIPanGestureRecognizer) { let curPoint = sender.locationInView(view)
let x = curPoint.x // 初始化3D变换,获取默认值
var perspectiveTransform = CATransform3DIdentity // 透视
perspectiveTransform.m34 = -1.0 / 2000.0 // 空间旋转
perspectiveTransform = CATransform3DRotate(perspectiveTransform, Math.RadianFromDegree(x * math.k), , , )
CATransaction.setDisableActions(true)
layer.transform = perspectiveTransform layer.contents = UIImage(named: x >= Width() / 2.0 ? "pic_2" : "pic_1")?.CGImage if sender.state == .Ended { // 初始化3D变换,获取默认值
var perspectiveTransform = CATransform3DIdentity // 透视
perspectiveTransform.m34 = -1.0 / 2000.0 // 空间旋转
perspectiveTransform = CATransform3DRotate(perspectiveTransform, Math.RadianFromDegree(x >= Width() / 2.0 ? : ), , , ) CATransaction.setDisableActions(false)
layer.transform = perspectiveTransform
}
}
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,031
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,520
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,368
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,148
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,781
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,860