2021-03-01 07:23:45 +01:00
|
|
|
//
|
|
|
|
// WelcomeIllustrationView.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by MainasuK Cirno on 2021-3-1.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
|
|
|
final class WelcomeIllustrationView: UIView {
|
|
|
|
|
2021-03-16 11:24:48 +01:00
|
|
|
static let artworkImageSize = CGSize(width: 375, height: 1500)
|
2021-03-02 06:45:47 +01:00
|
|
|
|
|
|
|
let cloudBaseImageView = UIImageView()
|
|
|
|
let rightHillImageView = UIImageView()
|
|
|
|
let leftHillImageView = UIImageView()
|
|
|
|
let centerHillImageView = UIImageView()
|
2021-03-16 11:24:48 +01:00
|
|
|
|
2021-04-14 09:24:54 +02:00
|
|
|
private let cloudBaseImage = Asset.Scene.Welcome.Illustration.cloudBase.image
|
|
|
|
private let elephantThreeOnGrassWithTreeTwoImage = Asset.Scene.Welcome.Illustration.elephantThreeOnGrassWithTreeTwo.image
|
|
|
|
private let elephantThreeOnGrassWithTreeThreeImage = Asset.Scene.Welcome.Illustration.elephantThreeOnGrassWithTreeThree.image
|
|
|
|
private let elephantThreeOnGrassImage = Asset.Scene.Welcome.Illustration.elephantThreeOnGrass.image
|
2021-03-01 10:38:45 +01:00
|
|
|
|
|
|
|
// layout outside
|
|
|
|
let elephantOnAirplaneWithContrailImageView: UIImageView = {
|
2021-04-14 09:24:54 +02:00
|
|
|
let imageView = UIImageView(image: Asset.Scene.Welcome.Illustration.elephantOnAirplaneWithContrail.image)
|
2021-03-01 10:38:45 +01:00
|
|
|
imageView.contentMode = .scaleAspectFill
|
|
|
|
return imageView
|
|
|
|
}()
|
|
|
|
|
2021-03-01 07:23:45 +01:00
|
|
|
override init(frame: CGRect) {
|
|
|
|
super.init(frame: frame)
|
|
|
|
_init()
|
|
|
|
}
|
|
|
|
|
|
|
|
required init?(coder: NSCoder) {
|
|
|
|
super.init(coder: coder)
|
|
|
|
_init()
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
extension WelcomeIllustrationView {
|
2021-03-02 06:45:47 +01:00
|
|
|
|
2021-03-01 07:23:45 +01:00
|
|
|
private func _init() {
|
2021-04-14 09:24:54 +02:00
|
|
|
backgroundColor = Asset.Scene.Welcome.Illustration.backgroundCyan.color
|
2021-03-01 10:38:45 +01:00
|
|
|
|
|
|
|
let topPaddingView = UIView()
|
|
|
|
|
|
|
|
topPaddingView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
addSubview(topPaddingView)
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
topPaddingView.topAnchor.constraint(equalTo: topAnchor),
|
|
|
|
topPaddingView.leadingAnchor.constraint(equalTo: leadingAnchor),
|
|
|
|
topPaddingView.trailingAnchor.constraint(equalTo: trailingAnchor),
|
|
|
|
])
|
|
|
|
|
2021-03-02 06:45:47 +01:00
|
|
|
cloudBaseImageView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
addSubview(cloudBaseImageView)
|
2021-03-01 10:38:45 +01:00
|
|
|
NSLayoutConstraint.activate([
|
2021-03-02 06:45:47 +01:00
|
|
|
cloudBaseImageView.topAnchor.constraint(equalTo: topPaddingView.bottomAnchor),
|
|
|
|
cloudBaseImageView.leadingAnchor.constraint(equalTo: leadingAnchor),
|
|
|
|
cloudBaseImageView.trailingAnchor.constraint(equalTo: trailingAnchor),
|
|
|
|
cloudBaseImageView.bottomAnchor.constraint(equalTo: bottomAnchor),
|
|
|
|
cloudBaseImageView.widthAnchor.constraint(equalTo: cloudBaseImageView.heightAnchor, multiplier: WelcomeIllustrationView.artworkImageSize.width / WelcomeIllustrationView.artworkImageSize.height),
|
2021-03-01 10:38:45 +01:00
|
|
|
])
|
2021-03-02 06:45:47 +01:00
|
|
|
|
|
|
|
[
|
|
|
|
rightHillImageView,
|
|
|
|
leftHillImageView,
|
|
|
|
centerHillImageView,
|
|
|
|
].forEach { imageView in
|
|
|
|
imageView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
addSubview(imageView)
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
imageView.topAnchor.constraint(equalTo: cloudBaseImageView.topAnchor),
|
|
|
|
imageView.leadingAnchor.constraint(equalTo: cloudBaseImageView.leadingAnchor),
|
|
|
|
imageView.trailingAnchor.constraint(equalTo: cloudBaseImageView.trailingAnchor),
|
|
|
|
imageView.bottomAnchor.constraint(equalTo: cloudBaseImageView.bottomAnchor),
|
|
|
|
])
|
|
|
|
}
|
2021-03-01 10:38:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
override func layoutSubviews() {
|
|
|
|
super.layoutSubviews()
|
2021-03-02 06:45:47 +01:00
|
|
|
updateImage()
|
2021-03-01 10:38:45 +01:00
|
|
|
}
|
|
|
|
|
2021-03-02 06:45:47 +01:00
|
|
|
private func updateImage() {
|
|
|
|
let size = WelcomeIllustrationView.artworkImageSize
|
|
|
|
let width = size.width
|
|
|
|
let height = size.height
|
|
|
|
|
|
|
|
cloudBaseImageView.image = UIGraphicsImageRenderer(size: size).image { context in
|
2021-03-01 10:38:45 +01:00
|
|
|
// clear background
|
|
|
|
UIColor.clear.setFill()
|
2021-03-02 06:45:47 +01:00
|
|
|
context.fill(CGRect(origin: .zero, size: size))
|
2021-03-16 11:24:48 +01:00
|
|
|
|
2021-03-01 10:38:45 +01:00
|
|
|
// draw cloud
|
|
|
|
cloudBaseImage.draw(at: CGPoint(x: 0, y: height - cloudBaseImage.size.height))
|
2021-03-02 06:45:47 +01:00
|
|
|
}
|
2021-03-16 11:24:48 +01:00
|
|
|
|
2021-03-02 06:45:47 +01:00
|
|
|
rightHillImageView.image = UIGraphicsImageRenderer(size: size).image { context in
|
|
|
|
// clear background
|
|
|
|
UIColor.clear.setFill()
|
|
|
|
context.fill(CGRect(origin: .zero, size: size))
|
|
|
|
|
2021-03-16 11:24:48 +01:00
|
|
|
// draw elephantThreeOnGrassWithTreeTwoImage
|
|
|
|
// elephantThreeOnGrassWithTreeTwo.bottomY - 25 align to elephantThreeOnGrassImage.centerY
|
|
|
|
elephantThreeOnGrassWithTreeTwoImage.draw(at: CGPoint(x: width - elephantThreeOnGrassWithTreeTwoImage.size.width, y: height - 0.5 * elephantThreeOnGrassImage.size.height - elephantThreeOnGrassWithTreeTwoImage.size.height + 25))
|
2021-03-02 06:45:47 +01:00
|
|
|
}
|
2021-03-16 11:24:48 +01:00
|
|
|
|
2021-03-02 06:45:47 +01:00
|
|
|
leftHillImageView.image = UIGraphicsImageRenderer(size: size).image { context in
|
|
|
|
// clear background
|
|
|
|
UIColor.clear.setFill()
|
|
|
|
context.fill(CGRect(origin: .zero, size: size))
|
2021-03-16 11:24:48 +01:00
|
|
|
|
|
|
|
// draw elephantThreeOnGrassWithTreeThree
|
|
|
|
// elephantThreeOnGrassWithTreeThree.bottomY + 30 align to elephantThreeOnGrassImage.centerY
|
|
|
|
elephantThreeOnGrassWithTreeThreeImage.draw(at: CGPoint(x: 0, y: height - 0.5 * elephantThreeOnGrassImage.size.height - elephantThreeOnGrassWithTreeThreeImage.size.height - 30))
|
2021-03-02 06:45:47 +01:00
|
|
|
}
|
2021-03-16 11:24:48 +01:00
|
|
|
|
2021-03-02 06:45:47 +01:00
|
|
|
centerHillImageView.image = UIGraphicsImageRenderer(size: size).image { context in
|
|
|
|
// clear background
|
|
|
|
UIColor.clear.setFill()
|
|
|
|
context.fill(CGRect(origin: .zero, size: size))
|
|
|
|
|
2021-03-01 10:38:45 +01:00
|
|
|
// draw elephantThreeOnGrass
|
|
|
|
elephantThreeOnGrassImage.draw(at: CGPoint(x: 0, y: height - elephantThreeOnGrassImage.size.height))
|
2021-03-02 06:45:47 +01:00
|
|
|
}
|
2021-03-01 07:23:45 +01:00
|
|
|
}
|
2021-03-01 11:32:31 +01:00
|
|
|
|
2021-03-01 07:23:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#if canImport(SwiftUI) && DEBUG
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct WelcomeIllustrationView_Previews: PreviewProvider {
|
|
|
|
|
|
|
|
static var previews: some View {
|
2021-03-01 10:38:45 +01:00
|
|
|
Group {
|
|
|
|
UIViewPreview(width: 375) {
|
|
|
|
WelcomeIllustrationView()
|
|
|
|
}
|
2021-03-16 11:24:48 +01:00
|
|
|
.previewLayout(.fixed(width: 375, height: 1500))
|
|
|
|
UIViewPreview(width: 1125) {
|
2021-03-01 10:38:45 +01:00
|
|
|
WelcomeIllustrationView()
|
|
|
|
}
|
2021-03-16 11:24:48 +01:00
|
|
|
.previewLayout(.fixed(width: 1125, height: 5000))
|
2021-03-01 07:23:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|