overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad() loadBackground() } func loadBackground(){ if(UIApplication.sharedApplication().statusbarOrIEntation.isPortrait){ var bgImage = UIImage(named: "bg-port") var background = UIImageVIEw(frame: self.vIEw.bounds); background.image = bgImage self.vIEw.addSubvIEw(background) self.vIEw.sendSubvIEwToBack(background) println(bgImage) } else { var bgImage = UIImage(named: "bg-land") var background = UIImageVIEw(frame: self.vIEw.bounds); background.image = bgImage self.vIEw.addSubvIEw(background) self.vIEw.sendSubvIEwToBack(background) println(bgImage) } } overrIDe func dIDRotateFromInterfaceOrIEntation(fromInterfaceOrIEntation: UIInterfaceOrIEntation) { loadBackground() }解决方法 它没有改变,因为你将新添加的UIImageVIEw发送到以前创建的UIImageVIEw的后面.而不是这样做,在你的类中为UIImageVIEw创建一个成员变量. (将其命名为背景)
func loadBackground(){ if self.background == nil { self.background = UIImageVIEw() self.vIEw.addSubvIEw(self.background) self.vIEw.sendSubvIEwToBack(self.background) } if(UIApplication.sharedApplication().statusbarOrIEntation.isPortrait) { var bgImage = UIImage(named: "bg-port") self.background.frame = self.vIEw.bounds; self.background.image = bgImage } else { var bgImage = UIImage(named: "bg-land") self.background.frame = self.vIEw.bounds; background.image = bgImage }}
但最好在界面中添加UIImageVIEw插座并使用代码加载图像,而不是在运行时创建一个.我更喜欢这将是一个很好的方法.
总结以上是内存溢出为你收集整理的ios – 更改方向更改的背景失败全部内容,希望文章能够帮你解决ios – 更改方向更改的背景失败所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)