Ios 在另一个类中调用UIView和NSLayoutConstraint时为nil
我想更改在情节提要中设置的约束的.常量值。每次我试图设置要传递给inout函数的变量时,我得到nil。任何帮助都将不胜感激。我将在下面列出这个问题 斯威夫特Ios 在另一个类中调用UIView和NSLayoutConstraint时为nil,ios,swift,uiview,nslayoutconstraint,Ios,Swift,Uiview,Nslayoutconstraint,我想更改在情节提要中设置的约束的.常量值。每次我试图设置要传递给inout函数的变量时,我得到nil。任何帮助都将不胜感激。我将在下面列出这个问题 斯威夫特 override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { // // call function on WheelViewController to display alert that wheel spinning //
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)
我试图在一个类中获取UIView、genieBusyAlertView和NSLayoutConstraint genieBottomLayoutConstraint,将它们传递到另一个类上的函数中,以更新约束常量,使其具有动画效果。任何帮助都会很棒。提前感谢您在这个问题上花费的时间和脑力。仅供参考。我能够为这个视图设置动画,并在函数外的同一个类中更改常量……在加载所有子视图后,我也成功地这样做了……但无法按照我需要的方式工作。你怎么能对“var view:UIView=WheelViewController().genieBusyAlertView”如此确定以正确引用WheelViewController引用。WheelViewController将加载对WheelViewController的新引用,并且不会考虑genieBusyAlertView,因为WheelViewController不是从情节提要中创建的?好问题@ldindu。那么,如何从SpinningWheel类运行位于WheelViewController中的函数呢?每次我运行它时,在该函数中,它在debug中显示UIView和设置了IBOutlets的NSLayoutConstraint为nil。这是怎么回事?什么是SpinningWheel、视图控制器或类?什么是SpinningWheel、视图控制器或视图?仅供参考。我能够为这个视图设置动画,并在函数外的同一个类中更改常量……在加载所有子视图后,我也成功地这样做了……但无法按照我需要的方式工作。你怎么能对“var view:UIView=WheelViewController().genieBusyAlertView”如此确定以正确引用WheelViewController引用。WheelViewController将加载对WheelViewController的新引用,并且不会考虑genieBusyAlertView,因为WheelViewController不是从情节提要中创建的?好问题@ldindu。那么,如何从SpinningWheel类运行位于WheelViewController中的函数呢?每次我运行它时,在该函数中,它在debug中显示UIView和设置了IBOutlets的NSLayoutConstraint为nil。这是怎么回事?什么是SpinningWheel、视图控制器或类?什么是SpinningWheel、视图控制器或视图?
@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
})
}