logo
down
shadow

Auto Layout UIView on constraint change does not animate iOS 7


Auto Layout UIView on constraint change does not animate iOS 7

By : Anil Vasani
Date : November 19 2020, 01:01 AM
seems to work fine If you replace [self.view layoutIfNeeded] with [self.aVC.view layoutIfNeeded], it would work on both iOS versions. I don't know the specific reason though.
Edit.
code :
[self.aVC.view layoutIfNeeded];
[UIView animateWithDuration:2 animations:^{
    constraint.constant = -25;
    [self.view layoutIfNeeded];
}];


Share : facebook icon twitter icon
Auto Layout constraint change does not animate

Auto Layout constraint change does not animate


By : jimmy
Date : March 29 2020, 07:55 AM
This might help you I was learning the auto layout with animations from the tutorial , I found the answer.
Instead of,
code :
[settingsView layoutIfNeeded];
[self.view layoutIfNeeded];
Animate UIView height when using auto layout with swift

Animate UIView height when using auto layout with swift


By : Christophe Gevrey
Date : March 29 2020, 07:55 AM
wish helps you Give your backgroundView a height constraint, and make an IBOutlet to it. In code, modify the constraint's constant value.
code :
func AnimateBackgroundHeight() {
    UIView.animateWithDuration(0.5, animations: {
         self.heightCon.constant = 600 // heightCon is the IBOutlet to the constraint
         self.view.layoutIfNeeded()    
    })
}
Animate auto-layout constraint constant X to the center of the parent view

Animate auto-layout constraint constant X to the center of the parent view


By : user3666190
Date : March 29 2020, 07:55 AM
I hope this helps you . Solved. Despite @matt great answer(and working). The main purpose of my question was handling the constraints constant in order to center it on the X. By the formula that might showed me :
code :
**a1 = m*a2 + c**
a1 = m*a2 + c
c = a1 - m* a2
c = self.view.center.x - 3 * self.view.center.x
c = -2 * self.view.center.x
 UIView.animateWithDuration(0.5, animations: { () -> Void in
                self.btn_option_layout.constant = -2 * self.nan_view.center.x
                self.nan_view.layoutIfNeeded()

            })
UIView.animateWithDuration(0.5, animations: { () -> Void 
 self.btn_option_layout.constant = 0     
 self.nan_view.layoutIfNeeded()

            })
In Swift, how do I animate a UIView with auto-layout like a page sliding in?

In Swift, how do I animate a UIView with auto-layout like a page sliding in?


By : Nemours
Date : March 29 2020, 07:55 AM
hop of those help? In my original question, I thought I was overwriting an existing rule (the left anchor) but actually I was creating a new rule for the left anchor, therefore the conflict and failure to animate.
With the help from @vacawama in the other question about changing AutoLayout rule, it is working now as below:
code :
override func viewDidLoad() {
    super.viewDidLoad()

    let myView = UIView()
    myView.backgroundColor = UIColor.orangeColor()
    myView.translatesAutoresizingMaskIntoConstraints = false
    view.addSubview(myView)

    myView.topAnchor.constraintEqualToAnchor(view.topAnchor).active = true
    myView.widthAnchor.constraintEqualToAnchor(view.widthAnchor).active = true
    myView.heightAnchor.constraintEqualToAnchor(view.heightAnchor).active = true

    var leftConstraint = myView.leftAnchor.constraintEqualToAnchor(view.rightAnchor)
    leftConstraint?.active = true

    myView.layoutIfNeeded()

    /* try to deactivate a rule and create a new rule, then animate it */
    leftConstraint?.active = false
    leftConstraint = myView.leftAnchor.constraintEqualToAnchor(view.leftAnchor)
    leftConstraint?.active = true

    UIView.animateWithDuration(1.0) { self.view.layoutIfNeeded() }
}
Animate UIView's Layer with constrains (Auto Layout Animations)

Animate UIView's Layer with constrains (Auto Layout Animations)


By : Nice Angel
Date : March 29 2020, 07:55 AM
wish helps you I know it's a tricky question. Actually, you don't need to care about layoutSubViews at all. The key here is when you set the shapeLayer. If it's setup well, i.e. after the constraints are all working, you don't need to care that during the animation.
//in CustomView, comment out the layoutSubViews() and add updateLayer()
code :
 func updateLayer(){
    guard let layer = self.layer as? CAShapeLayer else { return }
    layer.path = UIBezierPath(roundedRect: layer.bounds, cornerRadius: 10).cgPath
    layer.shadowPath = layer.path
}

  //    override func layoutSubviews() {
  //        super.layoutSubviews()
  //
  //        // While animating `myView` height, this method gets called
  //        // So new bounds for layer will be calculated and set immediately
  //        // This result in not proper animation
  //
 //        // check by making below condition always true
 //
 //        if !self.isAnimating{ //if true{
//            guard let layer = self.layer as? CAShapeLayer else { return }
//
//            layer.path = UIBezierPath(roundedRect: bounds, cornerRadius: 10).cgPath
//            layer.shadowPath = layer.path
//        }
//    }
  override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    myView.updateLayer()
}

@objc func animateView(_ sender: UIButton){

    CATransaction.begin()
    CATransaction.setAnimationDuration(5.0)
    CATransaction.setAnimationTimingFunction(CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut))

    UIView.animate(withDuration: 5.0, animations: {

        self.heightConstarint?.constant = self.heightToAnimate
        // this will call `myView.layoutSubviews()`
        // and layer's new bound will set automatically
        // this causing layer to be directly jump to height 200, instead of smooth animation
        self.view.layoutIfNeeded()

    }) { (success) in
        self.myView.isAnimating = false
    } 
   ....
Related Posts Related Posts :
  • CordovaError: Promise rejected with non-error: Error code 65
  • How to append NSMutable strings into a UILabel
  • CustomCell label value does not change
  • Display ad in iAd Bannerview iAd Network
  • Warning: "Could not get traitsetID for iPhone11,6" (Assets.xcassets)
  • Changing root view controller after iOS app has loaded.
  • SocketRocket and iOS certificate pinning
  • Draggable UIButton Snap To a Circle Path
  • Running FireBase in the background
  • resizing UIPopoverController to fit UITableController
  • UICollectionView Exception Crash
  • targeting iOS5 - will it work on iOS6 also?
  • FBLoginView get email
  • Scale UIImages height to UIImageView height
  • Creating a custom progress indicator in ios
  • NSRunLoop API difference
  • Is it possible to inject custom settings into my iOS application "Notifications" settings dialog?
  • UIAlertview not accepting string as message
  • Axis change of stackView giving layout error
  • How to use AVAssetResourceLoader?
  • How to write block definition using properties?
  • iOS connect/reconnect to Bluetooth device when using external-accessory and MFi
  • Saving XMPP Multi User chat messages through XMPP MessageArchiving in iOS
  • Deciding iOS version: pros and cons
  • iOS: Resigned app cannot access keychain through security API
  • How can I set To and Subject fields in an E-Mail being sent by UIDocumentInteractionController?
  • Updating uilabel in view controller underneath another
  • Maximum time Intervel for NSTimer
  • Delete Core Data Entry from Table View Controller
  • How to unload UIViewcontroller from memory?
  • Compressing UIImage as Far as Possible?
  • Optimizing workflow to update internally owned cocoapods dependencies?
  • Formatting an NSDate with Abbreviated Month/Day Names
  • I'm creating a quiz game with 4 answers and I want to add score
  • Tap Gesture to Hide Navigation Bar, Tab Bar, and Status Bar
  • FBSessionStateClosedLoginFailed when I am logged in through Settings
  • CGRect positioning according to center point
  • iOS: Update table view datasource with animations without core data
  • iOS : Where to start for AliPay integration?
  • Routing App Coverage File missing but not needed?
  • Drawing on a zoomable view
  • Append NSStrings and NSNumber to NSMutableArrays and make NSMutable dictionary
  • Terminating app due to uncaught exception 'NSRangeException' when calling dequeueReusableCellWithReuseIdentifier:forInde
  • Collision without physics (Cocos2D + Box2D iOS)
  • Creating a percentage based iOS layout
  • Update tableView row from AppDelegate Swift 4
  • Assigning return value of a class method to a variable error
  • how to display circular progress in delphi ios apps?
  • I can't figure how to fix this Expected identifier or '('
  • How to Test APIs in Swift 4?
  • Link error /Build/Products/Debug-iphonesimulator file not found
  • working with a very large JSON object in iOS
  • Turn off part of the iPhone Screen
  • Phonegap 3.0 app with facebook login using xCode
  • How to add interstitial admob ads to my ios project
  • adding tapku calendar to ios app
  • Add an alertcontroller in a global swift file?
  • Take square image with Cordova (Phonegap) Camera API?
  • Amazon S3 policy allowing only upload not overwrite
  • How to change the UILabel content by tapping?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org