-5
A
回答
1
可以撼動使用此功能
public func shakeView() {
let shake: CAKeyframeAnimation = CAKeyframeAnimation(keyPath: "transform")
shake.values = [NSValue(caTransform3D: CATransform3DMakeTranslation(-5.0, 0.0, 0.0)), NSValue(caTransform3D: CATransform3DMakeTranslation(5.0, 0.0, 0.0))]
shake.autoreverses = true
shake.repeatCount = 2.0
shake.duration = 0.07
self.layer.add(shake, forKey:"shake")
}
動搖視圖,您可以創建擴展或做小做下面的功能變化不大撼動任何視圖的任何視圖。
0
您可以通過CABasicAnimation
申請搖動動畫。
實施例:
class ViewController: UIViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
shakeAnimation()
}
func shakeAnimation() {
let animation = CABasicAnimation(keyPath: "position")
animation.duration = 0.3
animation.repeatCount = 10
animation.autoreverses = true
animation.fromValue = NSValue(cgPoint: CGPoint(x: self.view.center.x - 10, y: self.view.center.y))
animation.toValue = NSValue(cgPoint: CGPoint(x: self.view.center.x + 10, y: self.view.center.y))
self.view.layer.add(animation, forKey: "position")
}
}
結果:
0
寫的視圖爲它前一段時間。一切就緒裏面的界面生成器,鏈接視圖IBOutlet中,並呼籲:
shakeItView.shake(completion: { _ in })
代碼爲我的組件:
public final class ShakeItView: UIView {
public func shake(completion: @escaping (Bool) ->()) {
UIView.animate(withDuration: 0.07 - TimeInterval(count) * 0.01, delay: 0.01, options: .curveEaseInOut, animations: { [unowned self] in
self.transform = CGAffineTransform.init(translationX: CGFloat(10 * self.direction), y: 0)
}) { [unowned self] _ in
if self.count >= 4 {
self.transform = CGAffineTransform.identity
self.resetValues()
completion(true)
} else {
self.count += 1
self.direction *= -1
self.shake(completion: completion)
}
}
}
private var direction: Int = 1
private var count: Int = 0
private func resetValues() {
direction = 1
count = 0
}
}
相關問題
- 1. iOS谷歌登錄失敗
- 2. Facebook登錄失敗iOS 6
- 3. paypal IOS sdk登錄失敗
- 4. SQL登錄失敗,在創建表
- 5. 無法創建SQL Server Express的登錄 - 用戶登錄失敗
- 6. CodenameOne構建登錄失敗
- 7. 解析iOS的Facebook登錄失敗
- 8. iOS設備上的facebook登錄失敗
- 9. 如何創建一個動畫塊IOS
- 10. Android:如何創建Google Plus登錄動畫?
- 11. 如何Kerberos的SSO登錄失敗
- 12. 如何檢測失敗的Windows登錄
- 13. phpMyEdit登錄失敗?
- 14. GoogleAppengineLauncher登錄失敗
- 15. Google登錄失敗
- 16. JSF登錄失敗
- 17. Zend_OpenId_Consumer - 登錄失敗
- 18. dev.botframework.com登錄失敗
- 19. CakePHP登錄失敗
- 20. Facebook登錄失敗
- 21. Facebook登錄失敗
- 22. xrdp_mm_process_login_response:登錄失敗
- 23. Scrapy登錄失敗
- 24. phppgadmin登錄失敗
- 25. cakePHP登錄失敗
- 26. SqlBulkCopy登錄失敗
- 27. GoogleAppEngine登錄失敗
- 28. 登錄失敗juddi
- 29. Facebook登錄失敗
- 30. GoogleLoginService登錄失敗
添加代碼.. –
請將您的代碼,而不是一個截圖,但通過粘貼到你的問題。 – rckoenes