Thursday, 15 March 2012

ios - How to control the transition between 2 UIView states using a swipe gesture? -


I want to be able to swipe transition right gestures between the two states of a UIView with a swipe left. Basically I want to start increasing the height of the scene because the user starts swiping to the left and becomes "shrinking" when it swipe. I can easily animate with CAN Animation between the two states, but what I want is ideal that it is the signal to control the transition rather than giving it "duration". So essentially mapping the extension / shrinkage of the boundary height of the signal ... I am doing a terrible thing to explain to myself, but Apple is all this time.

Here's how it appears in your custom UIView moment:

  class CustomUIView: UIView {@IBOutlet bridesmaid swipeView: UIView! Var must have Except Expand Animation: Boole = True; Var needs extract shank animation: Bool = true; Required init (coder aDecoder in: NSCoder) {super.init (Coder: aDecoder) NSBundle.mainBundle () loadNibNamed ( "CustomUIView", the owner himself, option: zero). SwipeView.backgroundColor = UIColor.grayColor () self.addSubview (Self.swipeView) func performAnimation (Transansform: CATransform3D, toTransform: CATransform3D, duration: CFTimeInterval) {var animation: CABasicAnimation = CABasicAnimation (keyPath: "transform") animation. = self var transformView = conversion animation .fromValue = NSValue (CATransform3D: fromTransform) animation.toValue = NSValue (CATransform3D: toTransform) animation.duration = term self.swipeView.layer.addAnimation (animation, forKey: zero) self.swipeView.layer .transform = toTransform} expandView () {function if shouldExecuteExpandAnimation {performAnimation (CATransform3DIdentity, toTransform: CATransform3DMakeScale (1, 4, 1), duration: 0.1) executeShrinkAnimation = true; } ExxuteExpandAnimation = false; } Func shrinkView () {ifxexuteShrinkAnimation {executeAnimation (CATransform3DMakeScale (1, 4, 1), toTransform: CATransform3DMakeScale (1, 1, 1), duration: 0.1) shouldxecuteExpandAnimation = true} Chahiaakseksrenkanimeshn = false; } Func manageViewWithGesture {switch gestureRecognizer} {switch gestureResourceDescriptions {Case} UISwipeGestureRecognizerDirection.Right: expandView () Case UISwipeGestureRecognizerDirection.Left: shrinkView () Default: break}}}  

< Div class = "post-text" itemprop = "text">

As Aaron says, you can not get intermediate value with a swipe. If nothing happens, then it seems to be a fire, you have to use the pan gesture identifier or your own custom gesture identifier. For this, it is possible that you will be able to interpret the translation values ​​that you get from a standard pan-echchure identifier.

Then you can use those values ​​to change the animation from start to finish manually. I have a project on Gitbab which makes you different from ending the animation using the slider using the slider.

You can customize that approach to running an animation, because the user leaves a pan gesture.

View this link:


No comments:

Post a Comment