uiviewanimation
UIView animations with autoreverse
You have three options. When you use the -[UIView animateWithDuration:…] methods, the changes you make in the animations block are applied immediately to the views in question. However, there is also an implicit CAAnimation applied to the view that animates from the old value to the new value. When a CAAnimation is active on a … Read more
How to make UIView animation sequence repeat and autoreverse
To animation from point 1 to 2 to 3 to 2 to 1 and repeat, you can do use animateKeyframesWithDuration in iOS 7 and later: someView.frame = frame1; [UIView animateKeyframesWithDuration:2.0 delay:0.0 options:UIViewKeyframeAnimationOptionAutoreverse | UIViewKeyframeAnimationOptionRepeat animations:^{ [UIView addKeyframeWithRelativeStartTime:0.0 relativeDuration:0.5 animations:^{ someView.frame = frame2; }]; [UIView addKeyframeWithRelativeStartTime:0.5 relativeDuration:0.5 animations:^{ someView.frame = frame3; }]; } completion:nil]; If using … Read more
UIView animation based on UIPanGestureRecognizer velocity
The docs say The velocity of the pan gesture, which is expressed in points per second. The velocity is broken into horizontal and vertical components. So I’d say, given you want to move your view xPoints (measured in pt) to let it go off-screen, you could calculate the duration for that movement like so: CGFloat … Read more
UIView animation options using Swift
Swift 3 Pretty much the same as before: UIView.animate(withDuration: 0.2, delay: 0.2, options: UIViewAnimationOptions.repeat, animations: {}, completion: nil) except that you can leave out the full type: UIView.animate(withDuration: 0.2, delay: 0.2, options: .repeat, animations: {}, completion: nil) and you can still combine options: UIView.animate(withDuration: 0.2, delay: 0.2, options: [.repeat, .curveEaseInOut], animations: {}, completion: nil) Swift … Read more
UIView.animateWithDuration swift loop animation
No need to do the completion block approach, just use the animation options argument: updated for Swift 3.0 UIView.animate(withDuration: 2.0, delay: 0, options: [.repeat, .autoreverse], animations: { coloredSquare.frame = CGRect(x: 120, y: 220, width: 100, height: 100) }, completion: nil) If for any reason you want to stop the animation later, just use: coloredSquare.layer.removeAllAnimations()
iOS Segue – Left to Right –
This is how I achieve the effect without requiring a nav-controller. Try this instead: Swift 4: import UIKit class SegueFromLeft: UIStoryboardSegue { override func perform() { let src = self.source let dst = self.destination src.view.superview?.insertSubview(dst.view, aboveSubview: src.view) dst.view.transform = CGAffineTransform(translationX: -src.view.frame.size.width, y: 0) UIView.animate(withDuration: 0.25, delay: 0.0, options: .curveEaseInOut, animations: { dst.view.transform = CGAffineTransform(translationX: 0, … Read more
How to animate a UIView with constraints in Swift?
What you can do is to add the following code in your viewDidAppear method. You firstly make a IBOutlet property of your view’s center Y constraint, and then change its constant value. self.centerYConstraint.constant = 500.0 self.view.layoutIfNeeded() UIView.animateWithDuration(Double(0.5), animations: { self.centerYConstraint.constant = 0 self.view.layoutIfNeeded() })
UIButton can’t be touched while animated with UIView animateWithDuration
Swift 5 In my case, when I set button.alpha = 0, the button interaction stops working, no matter if I setup UIViewAnimationOptionAllowUserInteraction as an option. Reason Whenever you define the animation or not, the view’s property is applying to view’s layer immediately. Because of this, when you set the view.alpha=0, you hide the view completely. … Read more
iOS: How to convert UIViewAnimationCurve to UIViewAnimationOptions?
The category method you suggest is the “right” way to do it—you don’t necessarily have a guarantee of those constants keeping their value. From looking at how they’re defined, though, it seems you could just do animationOption = animationCurve << 16; …possibly with a cast to NSUInteger and then to UIViewAnimationOptions, if the compiler feels … Read more