当前位置:网站首页>Welcome page display
Welcome page display
2022-04-22 18:56:00 【Hanyang Li】
1. add to SDWebImage library , establish WelcomeViewController.swift Inherit UIViewController
import UIKit
import SDWebImage
class WelcomeViewController: UIViewController {
// Set the interface , The hierarchy of views
override func loadView() {
// Directly use the background image as the root view , Don't worry about the scaling of the image
view = backImageView
setupUI()
}
// Subsequent processing after the view is loaded , Usually used to set data
override func viewDidLoad() {
super.viewDidLoad()
// Load user avatar asynchronously
iconView.sd_setImage(with:UserAccountViewModel.sharedUserAccount.avatarUrl, placeholderImage: UIImage(named: "avatar_default_big"))
}
// The view is already displayed , You can usually animate / Keyboard processing
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
//1. Change constraints -> Change position
//updateConstraints Update already set constraints
//multiplier Properties are read-only properties , After creating , No modification allowed
/**
Develop with automatic layout , There is a principle
- All controls that use constraints to set positions , Don't set 'frame'
reason : The automatic layout system will be based on the set constraints , Automatically calculate the value of the control frame
stay layoutSubviews Function frme
If Active modification frame, Can cause Automatic layout system calculation error
- working principle : When a motion cycle starts , Automatic layout system , Will collect “ All constraints change ”
- Before the end of the rerun cycle , call layoutSubViews Functions are set uniformly frame
- If you want some constraints to be updated in advance ! Use ‘layoutIfNeeded’ Function to make the automatic layout system , Update the constraint changes currently collected in advance
*/
iconView.snp.updateConstraints { make in
// make.bottom.equalTo(view.snp.bottom).multipliedBy(0.3)
make.bottom.equalTo(view.snp.bottom).offset(-view.bounds.height + 200)
//make.bottom.equalTo(view.snp.bottom).offset(-view.bounds.height * 0.7)
}
//2. Animation
welcomeLable.alpha = 0
UIView.animate(withDuration: 1.2, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 10, options: []) {
// Modify all ‘ Animatable ’ attribute
// Automatic layout animation
self.view.layoutIfNeeded()
} completion: {(state: Bool) in
UIView.animate(withDuration: 0.7) {
self.welcomeLable.alpha = 1
} completion: {(state: Bool) in
// It's not recommended
//UIApplication.shared.keyWindow?.rootViewController = MainViewController()
NotificationCenter.default.post(name: NSNotification.Name(SwitchRootViewControllerNotification), object: nil)
}
}
}
//MARK: - Lazy load control
// background image
private lazy var backImageView:UIImageView = UIImageView(imageName: "ad_background")
// Head portrait
private lazy var iconView: UIImageView = {
let iv = UIImageView(imageName: "avatar_default_big")
// Setting fillet
iv.layer.cornerRadius = 45
iv.layer.masksToBounds = true
return iv
}()
// Welcome label
private lazy var welcomeLable: UILabel = UILabel(title: " welcome back ", fontSize: 18)
}
2. Extension class settings UI
//MARK: - Set the interface
extension WelcomeViewController{
private func setupUI(){
//1. add controls
view.addSubview(iconView)
view.addSubview(welcomeLable)
//2. Automatic layout
iconView.snp.makeConstraints { make in
make.centerX.equalTo(view.snp.centerX)
//make.bottom.equalTo(view.snp.bottom).multipliedBy(0.7)
make.bottom.equalTo(view.snp.bottom).offset(-200)
make.width.height.equalTo(90)
}
welcomeLable.snp.makeConstraints { make in
make.centerX.equalTo(iconView.snp.centerX)
make.top.equalTo(iconView.snp.bottom).offset(16)
}
}
}
版权声明
本文为[Hanyang Li]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204221854213608.html
边栏推荐
- 线性回归简洁实现
- 网络安全——Burp Suite抓包工具的使用
- Nat. Commun. | Neural coding framework for learning generation model
- 被删除的相片能恢复吗?3个技巧恢复被删除的相片
- server端密码加密
- 【CIcadplayer】进度条回调
- Cvpr2022 𞓜 collaborative dual stream visual language pre training model for cross modal retrieval
- There are so many operation and maintenance tools, which one to choose? Follow me for three seconds
- Stream demo
- High concurrency -- Deep parsing of the source code of the scheduledthreadpoolexecutor class
猜你喜欢

Nat. Commun. | Neural coding framework for learning generation model

On the ability of LAN chat software

2022語言與智能技術競賽再昇級,推出NLP四大前沿任務

错误 C4996 ‘fopen‘: This function or variable may be unsafe. Consider using fopen_s instead. To disabl

存储网络请求日志

2022 mise à niveau du concours de langues et de technologies intelligentes pour lancer les quatre tâches de pointe du PNL

微服务调用组件Feign介绍

B03基于STM32单片机独立按键控制数码管秒表Proteus设计、keil程序、c语言、源码,标准库版本

Kellerman Software . NET SFTP Library

fastjson的JSONObject数据保证顺序
随机推荐
线性回归简洁实现
leetcode 前缀和-题集
Pattern machine template computer CAD free pattern drawing and format conversion software ps300b tutorial: general CAD drawing and pattern drawing of Japanese brother pattern machine DXF file transfer
Mmdeploy quick start
每日AI前沿术语:绿色AI(Green AI)
系统分析师-论文写作 框架搭建
What does %[^\n] mean in C?
On the ability of LAN chat software
Introduction notes to PHP zero Foundation (12): array
RHCE-ansible
jsp学习(九.Filter过滤器、通配符和Cookie处理)
2019-12-07 wav音频剪切与合并
原来,这才是开发者打开世界读书日的正确姿势
RHCE-ansible
【洛谷】P2372 yyy2015c01挑战算周长(BFS)
nodejs如何预防xss攻击
062 deserialization vulnerability
2022年江西省安全员A证考试练习题及模拟考试
[untitled] 2022 coal mine outburst prevention test exercise and simulation test
2019-11-19 solve the problem that go test executes a single test file and prompts undefined