Esempio n. 1
0
        /// <summary>
        /// Clears the constraint's constant value.
        /// </summary>
        /// <param name="constraint">
        /// The constraint to clear.
        /// </param>
        /// <param name="didCreate">
        /// A value indicating whether did create.
        /// </param>
        public static void Clear(this NSLayoutConstraint constraint, bool didCreate)
        {
            if (constraint.Constant != 0)
            {
                NSNumber oldConstant = new NSNumber(constraint.Constant);
                constraint.Constant = 0;

                constraint.SetAssociatedObject(ConstantKey, oldConstant);
            }

            constraint.SetAssociatedObject(DidCreateKey, (NSNumber)didCreate);
        }
Esempio n. 2
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);
        }