Exemplo n.º 1
0
        /// <summary>
        /// Restores the constraint's constant value, if it is stored as an associated object.
        /// </summary>
        /// <param name="constraint">
        /// The constraint to restore.
        /// </param>
        /// <returns>
        /// Returns true if the constraint was created for the purpose of collapsing the view.
        /// </returns>
        public static bool Restore(this NSLayoutConstraint constraint)
        {
            NSNumber oldConstant = (NSNumber)constraint.GetAssociatedObject(ConstantKey);
            NSNumber didCreate   = (NSNumber)constraint.GetAssociatedObject(DidCreateKey);

            if (oldConstant != null)
            {
                constraint.Constant = oldConstant.FloatValue;
                constraint.SetAssociatedObject(ConstantKey, null);
            }

            if (didCreate == null)
            {
                return(false);
            }

            constraint.SetAssociatedObject(DidCreateKey, null);
            return(didCreate.BoolValue);
        }