//
// ViewTransitionViewControllerViewController.swift
// MFEfficiencyControl
//
// Created by changyou on 2022/4/22.
//
// view 翻页动画:微信读书的仿真动画就是这样实现的?
import UIKit
class ViewTransitionViewControllerViewController: UIViewController {
lazy var containerView: UIView = {
let containerView = UIView(frame: CGRect(x: 30,y: 100,width: 200,height: 300))
view.addSubview(containerView)
containerView.backgroundColor = .gray
return containerView
}()
lazy var redView: UIView = {
let redView = UIView(frame: CGRect(x: 0,y: 0,width: 200,height: 300))
view.addSubview(redView)
redView.backgroundColor = .gray
return redView
}()
lazy var orangeView: UIView = {
let orangeView = UIView(frame: CGRect(x: 0,y: 0,width: 200,height: 300))
view.addSubview(orangeView)
orangeView.backgroundColor = .gray
return orangeView
}()
enum ViewType {
case orange
case red
}
var currentType: ViewType = .orange
override func viewDidLoad() {
super.viewDidLoad()
containerView.addSubview(redView)
redView.frame.size = containerView.frame.size
redView.frame.origin = CGPoint(x: 0, y: 0)
containerView.addSubview(orangeView)
orangeView.frame.size = containerView.frame.size
orangeView.frame.origin = CGPoint(x: 0, y: 0)
}
@IBAction func transitionView(_ sender:Any) {
switch currentType {
case .orange:
UIView.transition(with: containerView, duration: 1.0,options: [.transitionCurlUp],animations: {
self.orangeView.removeFromSuperview()
self.containerView.addSubview(self.redView)
}) { (success) in
self.currentType = .red
}
case .red:
UIView.transition(with: containerView, duration: 1.0,options: [.transitionCurlUp],animations: {
self.redView.removeFromSuperview()
self.containerView.addSubview(self.orangeView)
}) { (success) in
self.currentType = .orange
}
}
}
}
网友评论