我有一个名为“ Home”的视图控制器,我想调用其方法之一,即myFunction()
。
let home = Home() as! UIViewController
home.myFunction()
这似乎不起作用。为什么?
如果Home是您的用户,rootViewController
则可以通过以下animateStuff
方法从AppDelegate方法中调用该方法:
if let viewController = self.window?.rootViewController? as? Home {
viewController.animateStuff()
}
如果Home
不是your rootViewContoller
,则必须检查presentedView
controller是否Home
在调用其方法:
if let viewController = self.window?.rootViewController.presentedViewController as? Home {
viewController.animateStuff()
}
最后看起来您的animateStuff方法应该首先将按钮设置为初始状态
func animateStuff(){
let optionsAnimateStuff = UIViewAnimationOptions.Repeat | UIViewAnimationOptions.Autoreverse | UIViewAnimationOptions.AllowUserInteraction
self.buttonPlay.transform = CGAffineTransformMakeScale(1.0, 1.0)
UIView.animateWithDuration(1.0, delay: 3.0, options:
optionsAnimateStuff, animations: {
self.buttonPlay.transform = CGAffineTransformMakeScale(1.13, 1.13)
}, completion: { finished in
})
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句