[英]How to implement the behaviour seen in the iOS lock screen when touching the camera icon?
I'm trying to implement the behaviour seen in the iOS lock screen when touching the camera icon, using a UIPageViewController 我正在尝试使用UIPageViewController来实现在触摸相机图标时在iOS锁定屏幕中看到的行为
I have a UIPageViewController that vertically scrolls between 2 view controllers. 我有一个UIPageViewController在2个视图控制器之间垂直滚动。 I would like to do a small "bounce/bump" when the user taps the view.
当用户点击视图时,我想做一个小的“反弹/碰撞”。
Any ideas on how I can accomplish this? 关于如何实现此目标的任何想法?
Thank you!! 谢谢!!
Thanks to @Szu for pointing me out to UIKit Dynamics :) 感谢@Szu向我指出UIKit Dynamics :)
Here's a rough solution: 这是一个粗略的解决方案:
Call init with a controller's view (to be bounced) and a reference view (your current view controller's view property). 使用控制器的视图(将被退回)和参考视图(您当前的视图控制器的view属性)调用init。
eg. 例如。
FSBounceAnimator(contentView: viewController.view, referenceView: self.view)
viewController is any viewController that you may instantiated and added as a childViewController viewController是您可以实例化并添加为childViewController的任何viewController。
self.view is your current viewController view. self.view是您当前的viewController视图。
Call bounce(), to bounce :) 调用bounce()进行反弹:)
import UIKit
class FSBounceAnimator: NSObject {
var animator: UIDynamicAnimator
var gravityBehaviour: UIGravityBehavior
var pushBehavior: UIPushBehavior
var itemBehaviour: UIDynamicItemBehavior
init(contentView: UIView!, referenceView: UIView!) {
animator = UIDynamicAnimator(referenceView: referenceView)
var colisionBehaviour: UICollisionBehavior = UICollisionBehavior(items: [contentView])
colisionBehaviour.setTranslatesReferenceBoundsIntoBoundaryWithInsets(UIEdgeInsetsMake(-100, 0, 0, 0))
animator.addBehavior(colisionBehaviour)
gravityBehaviour = UIGravityBehavior(items: [contentView])
gravityBehaviour.gravityDirection = CGVectorMake(1, 1)
animator.addBehavior(gravityBehaviour)
pushBehavior = UIPushBehavior(items: [contentView], mode: UIPushBehaviorMode.Instantaneous)
pushBehavior.magnitude = 0.0
pushBehavior.angle = 0.0
animator.addBehavior(pushBehavior)
itemBehaviour = UIDynamicItemBehavior(items: [contentView])
itemBehaviour.elasticity = 0.45
animator.addBehavior(itemBehaviour)
super.init()
}
func bounce() {
self.pushBehavior.pushDirection = CGVectorMake(0.0, 100.0);
self.pushBehavior.active = true;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.