iOS: UIView animation ignores delay

uiview.animate delay
uiview animate delay not working
ambiguous use of 'animatewithduration'
uiview.animate completion swift 4

I have a problem with very simple UIView animation:

- (void)showView:(CGFloat)delay
{
    [UIView animateWithDuration:1.0 delay:delay options:0 animations:^{

        // self.alpha = 0.5; // Works OK with delay
        self.frame = CGRectMake(100, 100, 100, 30); // delay is ignored
    } completion:nil];
}

delay could be set to 1000 and still view is animated immediately. But somehow it works fine with alpha (without setting frame).

UIView animation is done instantly without regards to the duration or , UIView animation is done instantly without regards to the duration or delay · ios swift uiviewanimation. I'm having some difficulties animating one  This method initiates a set of animations to perform on the view. The block object in the animations parameter contains the code for animating the properties of one or more views. During an animation, user interactions are temporarily disabled for the views being animated. (Prior to iOS 5, user interactions are disabled for the entire application.)

[self performSelector:@selector(animateMe) withObject:nil afterDelay:1000];

If self is viewController then you should use self.view.frame instead of self.frame. If self is view then you should use self.frame.

- (void)animateMe {

    [UIView animateWithDuration:1.0f animations:^{

        // self.alpha = 0.5; // Works OK with delay
        self.frame = CGRectMake(100, 100, 100, 30); // delay is ignored
    } completion:^(BOOL finished) {

        NSLog(@"Done");
    }];            
}

UIView's animateWithDuration delay not delaying animation, UIView's animateWithDuration delay not delaying animation · ios objective-c iphone block delay. I am trying to perform an animation on a label  In this tutorial, we’ll be animating our UI Views in various ways in the iOS Application. Table of Contents. 1 iOS UIView Animations 1.1 Animating Color. 1.2 Animate Movement. 1.3 Animate Size. 1.4 Animate Together. 2 Transform Animations. 3 Spring Animations 3.1 Transform Animation – Translate, Scale, Rotate.

This answer uses Swift, specifically version 4.2, and is tested in Xcode 10 playgrounds. This is actually my first try animating, and I'm very green with iOS in general, but this is how I solved the problem of delay not being observed.

import UIKit
import PlaygroundSupport

// Set up the main view
let liveViewFrame = CGRect(x: 0, y: 0, width: 500, height: 500)
let liveView = UIView(frame: liveViewFrame)
liveView.backgroundColor = .white

// Show the live view using the main view
PlaygroundPage.current.liveView = liveView

// Set up a smaller view for animation
let smallFrame = CGRect(x: 0, y: 0, width: 100, height: 100)
let square = UIView(frame: smallFrame)
square.backgroundColor = .purple

// Add the square to the live view ...
liveView.addSubview(square)

// ... and create an alias for it to allow delays to work.
// Calling square directly won't allow delays,
// giving it or the liveView subview an alias directly fails,
// and unwrapping (? or !) appears to fail as well.
// So, just call like `alias?.backgroundColor` ...
let squareView = square.superview?.subviews[0]

UIView.animate(withDuration: 1.5, delay: 1.0, options: [.repeat], animations: {
    //square.backgroundColor = .orange // this doesn't respect the delay arg
    squareView?.backgroundColor = .orange
    squareView?.frame = CGRect(x: 150, y: 150, width: 200, height: 200)
    squareView?.transform = CGAffineTransform(rotationAngle: CGFloat(Double.pi))
}, completion: nil)

This may not answer the question directly, but I believe similar logic could be applied for a workaround in related cases.

animateWithDuration:animations:completion:, animated. (Prior to iOS 5, user interactions are disabled for the entire application.) + animateWithDuration:delay:options:animations:completion: Animate  UIView animation is everywhere in iOS, and it’s a big part of what makes iOS apps so much fun. Thoughtfully chosen animations look great, and they can really bring your own iOS app to life. Better still, they’re also a great way to draw a user’s attention any time new or additional information becomes available in your app.

runningPropertyAnimator(withDuration:delay:options:animations , Creates and returns an animator object that begins running its animations immediately. SDKs. iOS 10.0+; Mac Catalyst 13.0+; tvOS 10.0+ class func runningPropertyAnimator(withDuration duration: TimeInterval, delay: TimeInterval​, options: UIView. options and options related to the animation direction are ignored. UIKit/ UIView Animations. UIView is the base class for any view that displays content in iOS apps. UIKit, the framework that gives us UIView, already provides us some basic animation functions which make it convenient for developers to achieve more by doing less.

UIView Animations Tutorial: Practical Recipes, In this UIView animations tutorial, you'll learn to build practical Update note: Nick Bonatsakis updated this tutorial for iOS 12, Xcode 10 and Swift 4.2 The code uses the UIView.animate(withDuration:delay:options:animations:completion​:) All rotations over a complete circle (360°) are ignored, and a 2π  The UIView Property Animator class lets you specify the duration and timing of your animations, but it performs the actual animations. You can pause a property-based animator that is currently running to interrupt the animation and drive it interactively.

UIView Animation Sequencing and Grouping Techniques – RPLabs , of animations in the animations property are currently ignored. The UIView animation methods are what developers are most familiar with. which can be used to specify a delay, animation curve, and block to be The code is available under the MIT license, and is compatible with iOS 4.0 and later. This value must be in the range 0 to 1, where 0 represents the start of the overall animation and 1 represents the end of the overall animation. For example, for an animation that is two seconds in duration, specifying a start time of 0.5 causes the animations to begin executing one second after the start of the overall animation.

Comments
  • Are you using auto layout?
  • @Fogmeister No. Starting animaion from superview also doesn't help
  • I have the similar problem. Moving code to -didMoveToSuperview can help with delay, but it is not very convenient.