UIView和NSLayoutConstraint在另一个类

时间:2016-08-08 20:30:34

标签: ios swift uiview nslayoutconstraint

我希望为故事板中设置的约束更改.constant值。每次我尝试将变量设置为传入inout函数时,我都会得到nil。任何帮助,将不胜感激。我将在下面解决这个问题。

SpinningWheel.swift

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {

 //
 // call function on WheelViewController to display alert that wheel spinning
 //
 var view: UIView = WheelViewController().genieBusyAlertView
 var constraint: NSLayoutConstraint = WheelViewController().genieBottomLayoutConstraint
 WheelViewController().wheelTappedWhileActive(&view, &constraint)

WheelViewController.swift

@IBOutlet var genieBusyAlertView: UIView!
@IBOutlet var genieBottomLayoutConstraint: NSLayoutConstraint!

override func viewDidLoad() {
    super.viewDidLoad()
 // the view or the constraint are referenced here, but they are in the storyboard.
}

func wheelTappedWhileActive(inout view: UIView, inout _ constraint: NSLayoutConstraint) {

    UIView.animateWithDuration(0.5, delay: 0.0, options: UIViewAnimationOptions.CurveEaseOut, animations: {

        constraint.constant = 251
        view.layoutIfNeeded()
        view.layer.shadowColor = UIColor.blackColor().CGColor
        view.layer.shadowOpacity = 0.7
        view.layer.shadowOffset = CGSizeZero
        view.layer.shadowRadius = 5
        }, completion: {(true) in

            //nothing here yet.
    })

    UIView.animateWithDuration(0.5, delay: 3.0, options: UIViewAnimationOptions.CurveEaseOut, animations: {

        constraint.constant = -100
        self.view.bringSubviewToFront(view)
        view.layoutIfNeeded()
        }, completion: {(true) in

            //nothing here yet
    })
}

我试图在一个类中抓取UIView,genieBusyAlertView和NSLayoutConstraint genieBottomLayoutConstraint,将它们传递到另一个类的函数中以更新约束常量,以便它将设置动画。任何帮助都是极好的。提前感谢你在这个问题上使用的任何时间和脑力。

0 个答案:

没有答案