Ces*_*are 2 ios appdelegate swift
我有一个名为"Home"的视图控制器,我想调用其中一个被调用的方法myFunction().
let home = Home() as! UIViewController
home.myFunction()
Run Code Online (Sandbox Code Playgroud)
这似乎不起作用.为什么?
如果Home是您的,rootViewController那么您可以animateStuff通过AppDelegate方法调用该方法:
if let viewController = self.window?.rootViewController? as? Home {
viewController.animateStuff()
}
Run Code Online (Sandbox Code Playgroud)
如果Home不是你的rootViewContoller,那么你必须检查presentedView控制器是否Home然后调用它的方法:
if let viewController = self.window?.rootViewController.presentedViewController as? Home {
viewController.animateStuff()
}
Run Code Online (Sandbox Code Playgroud)
最后看起来你的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
})
}
Run Code Online (Sandbox Code Playgroud)