国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|VB|R語(yǔ)言|JavaScript|易語(yǔ)言|vb.net|

香港云服务器
服務(wù)器之家 - 編程語(yǔ)言 - Swift - Swift仿微信語(yǔ)音通話最小化時(shí)后的效果實(shí)例代碼

Swift仿微信語(yǔ)音通話最小化時(shí)后的效果實(shí)例代碼

2021-12-23 15:18醉夢(mèng)弦音 Swift

這篇文章主要介紹了Swift仿微信語(yǔ)音通話最小化時(shí)后的效果的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

前言

最近碰到個(gè)需求,需要仿微信語(yǔ)音通話縮小化后,保持界面最上層有一個(gè)懸浮的小View可以一點(diǎn)擊就把剛剛縮放掉的界面再放回來(lái),其實(shí)本質(zhì)就是創(chuàng)造了一個(gè)新的Window,在這個(gè)window上創(chuàng)建了一個(gè)rootController并展示他,縮小化時(shí)是把controller dismiss掉了,再次點(diǎn)擊那個(gè)小View之后把這個(gè)controller再展示出來(lái)便可以了。同理微信小程序其實(shí)也是在一個(gè)新的Window中做了一套新的邏輯。隨著現(xiàn)在手機(jī)性能的提升,多Window同時(shí)存在并不會(huì)造成嚴(yán)重卡頓,而衍生出來(lái)的一種新的開(kāi)發(fā)方式。

實(shí)例代碼

上代碼,這個(gè)是根據(jù)網(wǎng)上找到的類似效果進(jìn)行了部分修改的,作者叫馮琦帆

SuspendTool

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import Foundation
import UIKit
 
enum SuspendType {
 case none
 case single
 case multi
}
 
class SuspendTool: NSObject {
 
 static let sharedInstance = SuspendTool()
 private var suspendWindows: [SuspendWindow] = []
// var semicircle: Semicircle?
 var origin: CGPoint = CGPoint.init(x: 10, y: 300)
 
 static func showSuspendWindow(rootViewController: UIViewController, coverImageName: String) {
 let tool = SuspendTool.sharedInstance
 let window = SuspendWindow.init(rootViewController: rootViewController, coverImageName: coverImageName, frame: CGRect.init(origin: tool.origin, size: CGSize.init(width: radious, height: radious)))
 window.show()
 tool.suspendWindows.append(window)
 }
 
 static func replaceSuspendWindow(rootViewController: UIViewController, coverImageName: String) {
 let tool = SuspendTool.sharedInstance
 tool.suspendWindows.removeAll()
 let window = SuspendWindow.init(rootViewController: rootViewController, coverImageName: coverImageName, frame: CGRect.init(origin: tool.origin, size: CGSize.init(width: radious, height: radious)))
 window.show()
 tool.suspendWindows.append(window)
 }
 
 static func remove(suspendWindow: SuspendWindow) {
 UIView.animate(withDuration: 0.25, animations: {
  suspendWindow.alpha = 0
 }) { (complete) in
  if let index = SuspendTool.sharedInstance.suspendWindows.index(of: suspendWindow) {
  SuspendTool.sharedInstance.suspendWindows.remove(at: index)
  }
 }
 }
 
 static func setLatestOrigin(origin: CGPoint) {
 SuspendTool.sharedInstance.origin = origin
 }
}

SuspendWindow

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import UIKit
 
let radious: CGFloat = 82
 
class SuspendWindow: UIWindow {
 
 fileprivate let coverImageName: String
 fileprivate let space: CGFloat = 15
 var containsRootViewController: UIViewController?
 
 init(rootViewController: UIViewController ,coverImageName: String, frame: CGRect) {
  self.coverImageName = coverImageName
  super.init(frame: frame)
  // self.rootViewController = rootViewController
  self.containsRootViewController = rootViewController
 }
 
 required init?(coder aDecoder: NSCoder) {
  fatalError("init(coder:) has not been implemented")
 }
 
 func show() {
  self.backgroundColor = UIColor.clear
  self.windowLevel = UIWindow.Level.alert - 1//UIWindowLevelAlert - 1
  self.screen = UIScreen.main
  self.isHidden = false
  
  let bgView = UIView()
  bgView.isUserInteractionEnabled = true
  bgView.frame = self.bounds
  bgView.backgroundColor = UIColor.white
  bgView.layer.cornerRadius = radious / 2.0
  bgView.layer.borderColor = UIColor.lightGray.cgColor
  bgView.layer.borderWidth = 5
  bgView.layer.masksToBounds = true
  self.addSubview(bgView)
  bgView.addSubview(iconImageView)
  bgView.addSubview(timeLabel)
  
  let panGesture = UIPanGestureRecognizer.init(target: self, action: #selector(didPan(_:)))
  self.addGestureRecognizer(panGesture)
  
  let tapGesture = UITapGestureRecognizer.init(target: self, action: #selector(didTap(_:)))
  self.addGestureRecognizer(tapGesture)
 }
 
 @objc fileprivate func didTap(_ tapGesture: UITapGestureRecognizer) {
  SuspendTool.sharedInstance.origin = self.frame.origin
  self.containsRootViewController?.spread(from: self.self.frame.origin)
  SuspendTool.remove(suspendWindow: self)
 }
 
 @objc fileprivate func didPan(_ panGesture: UIPanGestureRecognizer) {
  let point = panGesture.translation(in: panGesture.view)
  var originX = self.frame.origin.x + point.x
  if originX < space {
   originX = space
  } else if originX > UIScreen.main.bounds.width - radious - space {
   originX = UIScreen.main.bounds.width - radious - space
  }
  var originY = self.frame.origin.y + point.y
  if originY < space {
   originY = space
  } else if originY > UIScreen.main.bounds.height - radious - space {
   originY = UIScreen.main.bounds.height - radious - space
  }
  self.frame = CGRect.init(x: originX, y: originY, width: self.bounds.width, height: self.bounds.height)
  if panGesture.state == UIGestureRecognizer.State.cancelled || panGesture.state == UIGestureRecognizer.State.ended || panGesture.state == UIGestureRecognizer.State.failed {
   self.adjustFrameAfterPan()
  }
  panGesture.setTranslation(CGPoint.zero, in: self)
 }
 
 fileprivate func adjustFrameAfterPan() {
  var originX: CGFloat = space
  if self.center.x < UIScreen.main.bounds.width / 2 {
   originX = space
  } else if self.center.x >= UIScreen.main.bounds.width / 2 {
   originX = UIScreen.main.bounds.width - radious - space
  }
  UIView.animate(withDuration: 0.25, animations: {
   self.frame = CGRect.init(x: originX, y: self.frame.origin.y, width: self.frame.size.width, height: self.frame.size.height)
  }) { (complete) in
   SuspendTool.setLatestOrigin(origin: self.frame.origin)
  }
 }
 lazy var timeLabel: UILabel = {
  let timeLabel = UILabel()
  timeLabel.frame = CGRect(x: 0, y: 55.5, width: 42, height: 13)
  timeLabel.center.x = self.bounds.size.width / 2
  timeLabel.textAlignment = .center
  timeLabel.text = "0:00"
  timeLabel.textColor = UIColor.text
  timeLabel.font = UIFont.mediumFont(ofSize: 13)
  return timeLabel
 }()
 
 lazy var iconImageView: UIImageView = {
  let iconImageView = UIImageView.init(image: UIImage.init(named: coverImageName))
  iconImageView.isUserInteractionEnabled = true
  iconImageView.frame = CGRect(x: 0, y: 12, width: 38, height: 38)
  iconImageView.center.x = self.bounds.size.width / 2
  return iconImageView
 }()
}

UIViewController+FF

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import Foundation
import UIKit
 
extension UIViewController {
 
 func suspend(coverImageName: String, type: SuspendType) {
 if type == .none {
  self.navigationController?.popViewController(animated: true)
  return
 }
 self.view.layer.masksToBounds = true
 UIView.animate(withDuration: 0.25, animations: {
  self.view.layer.cornerRadius = radious / 2.0
  self.view.frame = CGRect.init(origin: SuspendTool.sharedInstance.origin, size: CGSize.init(width: radious, height: radious))
  self.view.layoutIfNeeded()
 }) { (complete) in
  self.navigationController?.popViewController(animated: false)
  if type == .single {
  SuspendTool.replaceSuspendWindow(rootViewController: self, coverImageName: coverImageName)
  } else {
  SuspendTool.showSuspendWindow(rootViewController: self, coverImageName: coverImageName)
  }
 }
 }
 
 func spread(from point: CGPoint) {
 if let isContain = self.navigationController?.viewControllers.contains(self), isContain {
  return
 }
 self.view.frame = CGRect.init(origin: point, size: CGSize.init(width: radious, height: radious))
 //UIViewController.currentViewController()
 
 UIViewController.currentViewController().navigationController?.pushViewController(self, animated: false)
 UIView.animate(withDuration: 0.25, animations: {
  self.view.layer.cornerRadius = 0
  self.view.frame = UIScreen.main.bounds
  self.view.layoutIfNeeded()
 })
 }
 
 static func currentViewController() -> UIViewController {
 var rootViewController: UIViewController? = nil
 for window in UIApplication.shared.windows {
  if (window.rootViewController != nil) {
  rootViewController = window.rootViewController
  break
  }
 }
 var viewController = rootViewController
 while (true) {
  if viewController?.presentedViewController != nil {
  viewController = viewController!.presentedViewController
  } else if viewController!.isKind(of: UINavigationController.self) {
  viewController = (viewController as! UINavigationController).visibleViewController
  } else if viewController!.isKind(of: UITabBarController.self) {
  viewController = (viewController as! UITabBarController).selectedViewController
  } else {
  break
  }
 }
 return viewController!
 }
 
}

總結(jié)

到此這篇關(guān)于Swift仿微信語(yǔ)音通話最小化時(shí)后效果的文章就介紹到這了,更多相關(guān)Swift微信語(yǔ)音通話最小化內(nèi)容請(qǐng)搜索服務(wù)器之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持服務(wù)器之家!

原文鏈接:https://juejin.cn/post/6935348223850577927

延伸 · 閱讀

精彩推薦
  • SwiftSwift教程之基礎(chǔ)數(shù)據(jù)類型詳解

    Swift教程之基礎(chǔ)數(shù)據(jù)類型詳解

    這篇文章主要介紹了Swift教程之基礎(chǔ)數(shù)據(jù)類型詳解,本文詳細(xì)講解了Swift中的基本數(shù)據(jù)類型和基本語(yǔ)法,例如常量和變量、注釋、分號(hào)、整數(shù)、數(shù)值類型轉(zhuǎn)換等...

    Swift教程網(wǎng)5162020-12-18
  • SwiftSwift中轉(zhuǎn)義閉包示例詳解

    Swift中轉(zhuǎn)義閉包示例詳解

    在Swift 中的閉包類似于結(jié)構(gòu)塊,并可以在任何地方調(diào)用,下面這篇文章主要給大家介紹了關(guān)于Swift中轉(zhuǎn)義閉包的相關(guān)資料,需要的朋友可以參考下...

    小小小_小朋友11412021-12-26
  • SwiftSwift使用CollectionView實(shí)現(xiàn)廣告欄滑動(dòng)效果

    Swift使用CollectionView實(shí)現(xiàn)廣告欄滑動(dòng)效果

    這篇文章主要為大家詳細(xì)介紹了Swift使用CollectionView實(shí)現(xiàn)廣告欄滑動(dòng)效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下...

    Stevin的技術(shù)博客12372021-01-13
  • SwiftSwift實(shí)現(xiàn)多個(gè)TableView側(cè)滑與切換效果

    Swift實(shí)現(xiàn)多個(gè)TableView側(cè)滑與切換效果

    這篇文章主要為大家詳細(xì)介紹了Swift實(shí)現(xiàn)多個(gè)TableView側(cè)滑與切換效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下...

    乞力馬扎羅的雪雪5822021-01-08
  • Swiftmac git xcrun error active developer path 錯(cuò)誤

    mac git xcrun error active developer path 錯(cuò)誤

    本文主要是講訴了如何解決在mac下使用git;xcode4.6的環(huán)境時(shí),出現(xiàn)了錯(cuò)誤(mac git xcrun error active developer path)的解決辦法,希望對(duì)大家有所幫助...

    Swift教程網(wǎng)2232020-12-16
  • Swiftswift where與匹配模式的實(shí)例詳解

    swift where與匹配模式的實(shí)例詳解

    這篇文章主要介紹了swift where與匹配模式的實(shí)例詳解的相關(guān)資料,這里附有簡(jiǎn)單的示例代碼,講的比較清楚,需要的朋友可以參考下...

    追到夢(mèng)的魔術(shù)師14382021-01-06
  • SwiftSwift能代替Objective-C嗎?

    Swift能代替Objective-C嗎?

    這是我在網(wǎng)上上看到的答案,復(fù)制粘貼過(guò)來(lái)和大家分享一下,因?yàn)槲液秃芏嗳艘粯雍荜P(guān)心Swift的出現(xiàn)對(duì)Mac開(kāi)發(fā)的影響和對(duì)Objective-C的影響。...

    Swift教程網(wǎng)4412020-12-16
  • SwiftSwift的74個(gè)常用內(nèi)置函數(shù)介紹

    Swift的74個(gè)常用內(nèi)置函數(shù)介紹

    這篇文章主要介紹了Swift的74個(gè)常用內(nèi)置函數(shù)介紹,這篇文章列舉出了所有的Swift庫(kù)函數(shù),內(nèi)置函數(shù)是指無(wú)需引入任何模塊即可以直接使用的函數(shù),需要的朋友可...

    Swift教程網(wǎng)5802020-12-19
810
主站蜘蛛池模板: 香蕉成人啪国产精品视频综合网 | 直接看av的网站 | av一区二区不卡 | 97超碰青青草 | 成人免费看黄 | 日韩中文字幕在线播放 | 久国产精品韩国三级视频 | 国产一区二区影院 | www.福利视频 | 成人午夜精品一区二区三区 | 在线激情视频 | 日韩精品一区二区三区四区五区 | 欧美日韩中文字幕在线 | 日韩一区二区三区在线观看 | 在线免费视频一区二区 | 亚洲国产精品久久久久 | 成人av高清在线观看 | 亚洲精彩视频在线 | 一区二区三区四区av | 黄工厂精品免费观看 | 国产精品视频在线播放 | 国产成人精品一区二区三区四区 | h在线免费 | 国产精品亚洲第一区在线暖暖韩国 | 毛片免费视频 | 韩国精品一区 | 国产亚洲一区二区精品 | 日日摸夜夜 | 天天躁人人躁人人躁狂躁 | 天天操天天干天天爽 | 亚洲精品免费播放 | 成人精品二区 | 超黄毛片 | 久久久成人精品 | 欧美一级片在线播放 | 久久噜 | 在线观看视频黄 | 国产黄色a级 | 亚洲h视频| 精品国产精品一区二区夜夜嗨 | 欧美视频网 |