var gandieImageView: UIImageView?
override func viewWillAppear(_ animated: Bool) {
...
updateAnimation()
}
override func viewDidDisappear(_ animated: Bool) {
gandieImageView?.image = nil
}
private func updateAnimation() {
let screenWidth = UIScreen.main.bounds.size.width
let screenHeight = UIScreen.main.bounds.size.height
let iconWidth: CGFloat = 82 // Fixed value by image size
let iconHeight: CGFloat = 81 // Fixed value by image size
let containerHeight: CGFloat = 64 // Fixed value by auto layout
//var topSafeAreaHeight: CGFloat = 0
var bottomSafeAreaHeight: CGFloat = 0
if #available(iOS 11.0, *) {
let window = UIApplication.shared.windows[0]
let safeFrame = window.safeAreaLayoutGuide.layoutFrame
//topSafeAreaHeight = safeFrame.minY // 取得top safe area高度
bottomSafeAreaHeight = window.frame.maxY - safeFrame.maxY // 取得 bottom safe area高度
}
let images = [UIImage(named: "move01")!, UIImage(named: "move02")!, UIImage(named: "move03")!, UIImage(named: "move04")!]
let animatedImage = UIImage.animatedImage(with: images, duration: 1)
// 建立UIImageView並設定初始位置
gandieImageView = UIImageView(frame: CGRect(
x: screenWidth + iconWidth,
y: screenHeight - bottomSafeAreaHeight - containerHeight - iconHeight - 5,
width: iconWidth,
height: iconHeight)
)
gandieImageView?.image = animatedImage
gandieImageView?.contentMode = .scaleAspectFit
// 要移到的位置
UIView.animate(withDuration: 1) {
self.gandieImageView?.frame = CGRect(
x: screenWidth - iconWidth - 5,
y: screenHeight - bottomSafeAreaHeight - containerHeight - iconHeight - 5,
width: iconWidth,
height: iconHeight
)
}
self.view.addSubview(gandieImageView!)
addGesture(imageView: gandieImageView)
}
實作相關
Ref. 防止重覆利用的 cell 顯示之前的照片
Jul 4, 2022Ref. Design Pattern
Jul 1, 2022Ref. Wifi Swift - Get device's WIFI IP Address Without Wifi:手機若開啟熱點時,可以掃到分享出去的網段 Swift - Get device's WIFI IP Address
Jun 23, 2022Ref. How to get the System font in an iOS app?
Jun 22, 2022or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up